C
C#•3y ago
Pounika

creating migration for a database

im trying to create a migration for my database but why does it give this error when AlarmMailMessage does have a .HasKey()?
25 Replies
Tvde1
Tvde1•3y ago
Do you understand what's wrong, if you read the error message? That's step 1
Pounika
PounikaOP•3y ago
it says it needs a primary key defined and in DbContext it gives details saying it has pk column named rowID i pulled these tables from an existing database in postgresql and it generated all this code, should i change it?
Tvde1
Tvde1•3y ago
hmm it should pick it up from the OnModelCreating otherwise try adding a [Key] attribute to the property
Yawnder
Yawnder•3y ago
Can you show a screenshot of your table in postgres admin page?
Pounika
PounikaOP•3y ago
the thing is that the database im using has tons of tables and when i imported the db it all got imported but im only gonna use like 2 of them and not this one that is giving the error
Yawnder
Yawnder•3y ago
Your column name is wrong in your mapping.
Pounika
PounikaOP•3y ago
i didnt write it tho so maybe thats what it read idk i also think its case insensitive
Yawnder
Yawnder•3y ago
Not sure what you mean.
Pounika
PounikaOP•3y ago
i mean the vs code is automatically generated
Yawnder
Yawnder•3y ago
It's irrelevant. In the code you've shown, you specify the name of the column as being alarmMailMessages_pkey.
Pounika
PounikaOP•3y ago
it was generated when i imported the db so should i change the code in the DbContext?
Yawnder
Yawnder•3y ago
I would. I'm wondering how it was generated wrong though.
Pounika
PounikaOP•3y ago
i changed it to rowID and im getting the same error
Yawnder
Yawnder•3y ago
Oh, I misread. It was the name of the PK, not the name of the column. Give me a sec then. It's weird that you get this error. Feels like it's not the actual DbContext used for the migration. Do you have another DbContext anywhere else?
Pounika
PounikaOP•3y ago
i have a dataContext that i created using this DbContext and i only wrote the tables im gonna use
Yawnder
Yawnder•3y ago
Can you show the $code of anything that inherits, directly or not, from DbContext?
MODiX
MODiX•3y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Pounika
PounikaOP•3y ago
im migrating using the dataContext here ok hol up
Pounika
PounikaOP•3y ago
BlazeBin - vznddooyussj
A tool for sharing your source code with the world!
Yawnder
Yawnder•3y ago
Ok, but that's not the DbContext you were talking about right? (there is no AlarmMailMessage in it)
Pounika
PounikaOP•3y ago
yea this is dataContext that im trying to do the migration DbContext has tons of tables but i needed only these
Yawnder
Yawnder•3y ago
I'm very confused. There is no AlarmMailMessage in that dataContext so there shouldn't be any migration message about that. I sadly have to go though.
Pounika
PounikaOP•3y ago
thanks for trying 😔✊
Tvde1
Tvde1•3y ago
are you using -c to select a context?
Pounika
PounikaOP•3y ago
Add-Migration createMigration -Context dataContext
Want results from more Discord servers?
Add your server