Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better compile error for entity without primary key #1020

Merged
merged 1 commit into from
Oct 6, 2022

Conversation

billy1624
Copy link
Member

@billy1624 billy1624 commented Sep 8, 2022

PR Info

Adds

  • Better compile error for entity without primary key.

Before:

---- src/lib.rs - derive_entity_model (line 116) stdout ----
error[E0412]: cannot find type `PrimaryKey` in this scope
 --> src/lib.rs:119:35
  |
5 | #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
  |                                   ^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the derive macro `sea_orm::prelude::DeriveEntity` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you might have meant to use the associated type
  |
5 | #[derive(Clone, Debug, PartialEq, Self::PrimaryKey)]
  |                                   ~~~~~~~~~~~~~~~~
help: consider importing one of these items
  |
2 | use sea_orm::tests_cfg::cake::PrimaryKey;
  |
2 | use sea_orm::tests_cfg::cake_expanded::PrimaryKey;
  |
2 | use sea_orm::tests_cfg::cake_filling::PrimaryKey;
  |
2 | use sea_orm::tests_cfg::cake_filling_price::PrimaryKey;
  |
    and 6 other candidates

error: aborting due to previous error

For more information about this error, try `rustc --explain E0412`.
Couldn't compile the test.

After:

---- src/lib.rs - derive_entity_model (line 116) stdout ----
error: Entity must have a primary key column. See <https://github.com/SeaQL/sea-orm/issues/485> for details.
 --> src/lib.rs:119:35
  |
5 | #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
  |                                   ^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the derive macro `DeriveEntityModel` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `_doctest_main_src_lib_rs_116_0::PrimaryKey: sea_orm::IdenStatic` is not satisfied
  --> src/lib.rs:119:35
   |
5  | #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
   |                                   ^^^^^^^^^^^^^^^^^ the trait `sea_orm::IdenStatic` is not implemented for `_doctest_main_src_lib_rs_116_0::PrimaryKey`
   |
   = help: the following other types implement trait `sea_orm::IdenStatic`:
             CakeFillingPrice
             LunchSet
             RustKeyword
             SelectA
             SelectB
             _doctest_main_src_lib_rs_116_0::Column
             _doctest_main_src_lib_rs_116_0::Entity
             sea_orm::tests_cfg::Cake
           and 26 others
note: required by a bound in `sea_orm::PrimaryKeyTrait`
  --> /Applications/MAMP/htdocs/sea-orm/src/entity/primary_key.rs:40:28
   |
40 | pub trait PrimaryKeyTrait: IdenStatic + Iterable {
   |                            ^^^^^^^^^^ required by this bound in `sea_orm::PrimaryKeyTrait`
   = note: this error originates in the derive macro `DeriveEntityModel` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
Couldn't compile the test.

@billy1624 billy1624 self-assigned this Sep 8, 2022
@billy1624 billy1624 linked an issue Sep 8, 2022 that may be closed by this pull request
@billy1624 billy1624 marked this pull request as ready for review September 8, 2022 09:51
@billy1624 billy1624 requested a review from tyt2y3 September 8, 2022 09:54
@tyt2y3 tyt2y3 merged commit 29deb0d into master Oct 6, 2022
@tyt2y3 tyt2y3 deleted the better-warning-entity-without-pk branch October 6, 2022 15:50
@tyt2y3
Copy link
Member

tyt2y3 commented Oct 6, 2022

Neat

@gitmalong
Copy link

In my case I am getting error messages for tables that have primary keys . See #2141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Handle tables with no primary keys
3 participants