71 Replies
alter table {table name}
alter column {columnname} varchar not null
where I'll write this?
as a query to your db
i never used VS that way, I just use mssms
@ZESS It looks like you're using ef, are you doing db first?
If not, then you shouldn't manually modify the database
yes
wait no
I made the class first
You're doing code first?
Okay so code first
yes
Then don't modify the database manually
Change the class and apply the new migration
I changed it here
No no no
but in database it doesn't change
Don't change the generated migration class manually
uff š
Can you show the class iteself?
yes
The class for the
joke
tablei change it later
make Joke ans int to string
Alright, apply a new migration then!
can you tell me how?
Add-Migration "setup2"
like this?
I guess so, I usually use
dotnet ef migrations add "name_goes_here"
But I think Add-Migration "name_goes_her" works
This will generate a new migration
And then Update-Database
Also make sure to revert the changes made to InitalSetup classhow can I delete the previous migration?
when I use update
Hmm, can you revert the changes first?
idk how
š
im new
Okay, do you have any data in the Joke table?
should I delet this?
no
Alright, open visual studio's git tools
I should start from the first
my bad
Sorry it's called Git changes
š
Right click on the InitialSetup.cs file here and "undo changes"
done
now?
update/
?
Okay remove the last migration
Remove-Migration
it said done
What do you have now in Data\Migrations folder?
Alright now
Add a new migration
should I remove & start a new migration?
Add-Migration "name_goes_here"
what about initial setup?
Keep it like that
Now update your database
Update-Database
View the joke table now
its good now
can you tell me
what you did?
if i face problem like this
should I delete the migration
& create new?
or what?
Sure thing
First we reverted the changes you manually made to the migrations file (the reason you had to revert it is because when a migrations class is generated it compares itself with the previous one, to keep track of whether the new migrations needs to change the column type or name, when you manually changed it, the generator basically can't really make sense of what's the difference)
Second we create a new migration with the updated column type
Third apply the new migration to the database
but what about initialsetup?
how to drop it?
You don't need to drop it, you only need to apply changes based on what's different between initialsetup and Dbnew
yes understood
but what if i want to delete it?
Delete it from the source code or the database as well?
Because the database keeps track of migrations applied
I understant
it just override the method
if I delete it
the db won't work
right?
Well, if you delete it the database will work, because after migrations are applied, they don't affect the database (until you need to apply a new migartion)
oh
so after finishing the project I can delete if i want
right?
You can, but you shouldn't really delete it, you should keep your migrations, but if you want to sure
got it.
can I dm you? I need few help but offtopic.
I prefer to keep communication here š
or can i say it here?
can you give me some discord link related to dotNet? & resources to learn dotnet core mvc?
I don't personally know any specific links for asp.net core mvc
You can check the official docs or ask over #web
oh
If you do want to ask any dotnet questions, you won't really find anything better than here (unless it's unity specific for example)
thanks for your help ā¤ļø
Np
Make sure to
/close