✅ 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
well, as it says.
you can't add/remove
IDENTITY
from a column once its been createdya but i delted the model
and it still doesnt work
i removed the model but it still shows in the database
you have provided zero context
ok so
so I have no frame of reference for what "model" means here
asp.net mvc
is this EF Core? Is it related to migrations?
yes
the error is from SQL server
so your migrations are wrong
they are trying to execute invalid sql
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
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?nope
well thats your problem
ill try
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
i thoguht it did that automatically
nope.
i did rmeove from db context
but it still shwoing in database and giving same error
@Pobiega
did you add and run the migration?
yes
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
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
yeah, remove all existing migrations + snapshot, delete your database, run add-migration, run update-database
that will create a "clean" slate
ok
hey now it say there is already an object in the database called aspNetroles but i jsut delted the database
then clearly your database wasnt really deleted
i did drop database
and also delted from the side
what database are you using? what program are you using to access the database?
locad db built in
SQL Express then
hot garbage, but its not your source of errors here.
lol
yesss it worked
I'd highly recommend learning how docker works and using a real
sqlserver
instance for the futureight
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!"okkk thank you very much
np
you can $close this thread if you are happy 🙂
Use the /close command to mark a forum thread as answered