C
C#11mo ago
🙈

✅ Change the IDENTITY property of a column, the column needs to be dropped and recreated

help Change the IDENTITY property of a column, the column needs to be dropped and recreated
36 Replies
Pobiega
Pobiega11mo ago
well, as it says. you can't add/remove IDENTITY from a column once its been created
🙈
🙈OP11mo ago
ya but i delted the model and it still doesnt work i removed the model but it still shows in the database
Pobiega
Pobiega11mo ago
you have provided zero context
🙈
🙈OP11mo ago
ok so
Pobiega
Pobiega11mo ago
so I have no frame of reference for what "model" means here
🙈
🙈OP11mo ago
asp.net mvc
Pobiega
Pobiega11mo ago
is this EF Core? Is it related to migrations?
🙈
🙈OP11mo ago
yes
Pobiega
Pobiega11mo ago
the error is from SQL server so your migrations are wrong they are trying to execute invalid sql
🙈
🙈OP11mo ago
no ill explain what happened i had a class called cusotmer with a int id i then watned to try and change it to a string id however i relasied this will not work so i delted the cusotmer class but it still shows in the database
Pobiega
Pobiega11mo ago
yes? once you deleted the class, did you also remove the DbSet<Customer> property on your context, remove any configuration for that property, and add a new migration?
🙈
🙈OP11mo ago
nope
Pobiega
Pobiega11mo ago
well thats your problem
🙈
🙈OP11mo ago
ill try
Pobiega
Pobiega11mo ago
any change to your database models MUST be followed by adding a new migration and running that migration otherwise, yes your DB will get out of sync
🙈
🙈OP11mo ago
i thoguht it did that automatically
Pobiega
Pobiega11mo ago
nope.
🙈
🙈OP11mo ago
i did rmeove from db context but it still shwoing in database and giving same error @Pobiega
Pobiega
Pobiega11mo ago
did you add and run the migration?
🙈
🙈OP11mo ago
yes
Pobiega
Pobiega11mo ago
thats what actually pushes your changes to the database. check the migration, did it add a table drop instruction somewhere? you probably have a bad migration somewhere, I'd consider deleting them all and recreating from scratch if I were you
🙈
🙈OP11mo ago
wait i refresh the database but wehn i run update-database i get error and cusotmer tabel is still there it says build succed should i delete the database is there a way to remove all perviosu migrations this is so annoying @Pobiega
Pobiega
Pobiega11mo ago
yeah, remove all existing migrations + snapshot, delete your database, run add-migration, run update-database that will create a "clean" slate
🙈
🙈OP11mo ago
ok hey now it say there is already an object in the database called aspNetroles but i jsut delted the database
Pobiega
Pobiega11mo ago
then clearly your database wasnt really deleted
🙈
🙈OP11mo ago
i did drop database and also delted from the side
Pobiega
Pobiega11mo ago
what database are you using? what program are you using to access the database?
🙈
🙈OP11mo ago
locad db built in
Pobiega
Pobiega11mo ago
SQL Express then hot garbage, but its not your source of errors here.
🙈
🙈OP11mo ago
lol yesss it worked
Pobiega
Pobiega11mo ago
I'd highly recommend learning how docker works and using a real sqlserver instance for the future
🙈
🙈OP11mo ago
ight
Pobiega
Pobiega11mo ago
and no, there is nothing automatic about updating databases every single change to an entity or the context itself MUST be followed by add-migration and I suggest you manually read and verify the migrations it creates generated migrations cant adjust your data as needed, they are a "base" that you can expand upon you must also verify that the migration matches what you expected. I for one very often see it generate nvarchar(max) columns and I go "oof, I forgot to put a max length there!"
🙈
🙈OP11mo ago
okkk thank you very much
Pobiega
Pobiega11mo ago
np you can $close this thread if you are happy 🙂
MODiX
MODiX11mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server