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
Do you understand what's wrong, if you read the error message? That's step 1
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?
hmm it should pick it up from the OnModelCreating
otherwise try adding a
[Key]
attribute to the propertyCan you show a screenshot of your table in postgres admin page?
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
Your column name is wrong in your mapping.
i didnt write it tho so maybe thats what it read idk
i also think its case insensitive
Not sure what you mean.
i mean the vs code is automatically generated
It's irrelevant. In the code you've shown, you specify the name of the column as being
alarmMailMessages_pkey
.it was generated when i imported the db so should i change the code in the DbContext?
I would. I'm wondering how it was generated wrong though.
i changed it to rowID and im getting the same error
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?
i have a dataContext that i created using this DbContext and i only wrote the tables im gonna use
Can you show the $code of anything that inherits, directly or not, from DbContext?
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/im migrating using the dataContext here
ok hol up
BlazeBin - vznddooyussj
A tool for sharing your source code with the world!
Ok, but that's not the DbContext you were talking about right?
(there is no
AlarmMailMessage
in it)yea this is dataContext that im trying to do the migration
DbContext has tons of tables but i needed only these
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.thanks for trying 😔✊
are you using -c to select a context?
Add-Migration createMigration -Context dataContext