C
C#ā€¢11mo ago
ZESS

āœ… Change Table Row dataType?

How can I change it to Int to Varchar?
71 Replies
friedice
friediceā€¢11mo ago
alter table {table name} alter column {columnname} varchar not null
ZESS
ZESSā€¢11mo ago
where I'll write this?
ZESS
ZESSā€¢11mo ago
friedice
friediceā€¢11mo ago
as a query to your db i never used VS that way, I just use mssms
Kouhai
Kouhaiā€¢11mo ago
@ZESS It looks like you're using ef, are you doing db first? If not, then you shouldn't manually modify the database
ZESS
ZESSā€¢11mo ago
yes wait no I made the class first
Kouhai
Kouhaiā€¢11mo ago
You're doing code first? Okay so code first
ZESS
ZESSā€¢11mo ago
yes
Kouhai
Kouhaiā€¢11mo ago
Then don't modify the database manually Change the class and apply the new migration
ZESS
ZESSā€¢11mo ago
I changed it here
Kouhai
Kouhaiā€¢11mo ago
No no no
ZESS
ZESSā€¢11mo ago
but in database it doesn't change
Kouhai
Kouhaiā€¢11mo ago
Don't change the generated migration class manually
ZESS
ZESSā€¢11mo ago
uff šŸ™‚
Kouhai
Kouhaiā€¢11mo ago
Can you show the class iteself?
ZESS
ZESSā€¢11mo ago
yes
Kouhai
Kouhaiā€¢11mo ago
The class for the joke table
ZESS
ZESSā€¢11mo ago
ZESS
ZESSā€¢11mo ago
i change it later make Joke ans int to string
Kouhai
Kouhaiā€¢11mo ago
Alright, apply a new migration then!
ZESS
ZESSā€¢11mo ago
can you tell me how? Add-Migration "setup2" like this?
Kouhai
Kouhaiā€¢11mo ago
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 class
ZESS
ZESSā€¢11mo ago
how can I delete the previous migration?
ZESS
ZESSā€¢11mo ago
when I use update
Kouhai
Kouhaiā€¢11mo ago
Hmm, can you revert the changes first?
ZESS
ZESSā€¢11mo ago
idk how šŸ™‚ im new
Kouhai
Kouhaiā€¢11mo ago
Okay, do you have any data in the Joke table?
ZESS
ZESSā€¢11mo ago
should I delet this?
ZESS
ZESSā€¢11mo ago
no
Kouhai
Kouhaiā€¢11mo ago
Alright, open visual studio's git tools
ZESS
ZESSā€¢11mo ago
ZESS
ZESSā€¢11mo ago
I should start from the first my bad
Kouhai
Kouhaiā€¢11mo ago
Kouhai
Kouhaiā€¢11mo ago
Sorry it's called Git changes šŸ˜…
ZESS
ZESSā€¢11mo ago
Kouhai
Kouhaiā€¢11mo ago
Right click on the InitialSetup.cs file here and "undo changes"
ZESS
ZESSā€¢11mo ago
done
ZESS
ZESSā€¢11mo ago
now? update/ ?
Kouhai
Kouhaiā€¢11mo ago
Okay remove the last migration Remove-Migration
ZESS
ZESSā€¢11mo ago
it said done
Kouhai
Kouhaiā€¢11mo ago
What do you have now in Data\Migrations folder?
ZESS
ZESSā€¢11mo ago
Kouhai
Kouhaiā€¢11mo ago
Alright now Add a new migration
ZESS
ZESSā€¢11mo ago
should I remove & start a new migration?
Kouhai
Kouhaiā€¢11mo ago
Add-Migration "name_goes_here"
ZESS
ZESSā€¢11mo ago
what about initial setup?
Kouhai
Kouhaiā€¢11mo ago
Keep it like that
ZESS
ZESSā€¢11mo ago
Kouhai
Kouhaiā€¢11mo ago
Now update your database Update-Database
ZESS
ZESSā€¢11mo ago
Kouhai
Kouhaiā€¢11mo ago
View the joke table now
ZESS
ZESSā€¢11mo ago
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?
Kouhai
Kouhaiā€¢11mo ago
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
ZESS
ZESSā€¢11mo ago
but what about initialsetup?
ZESS
ZESSā€¢11mo ago
how to drop it?
Kouhai
Kouhaiā€¢11mo ago
You don't need to drop it, you only need to apply changes based on what's different between initialsetup and Dbnew
ZESS
ZESSā€¢11mo ago
yes understood but what if i want to delete it?
Kouhai
Kouhaiā€¢11mo ago
Delete it from the source code or the database as well? Because the database keeps track of migrations applied
ZESS
ZESSā€¢11mo ago
I understant
ZESS
ZESSā€¢11mo ago
it just override the method if I delete it the db won't work right?
Kouhai
Kouhaiā€¢11mo ago
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)
ZESS
ZESSā€¢11mo ago
oh so after finishing the project I can delete if i want right?
Kouhai
Kouhaiā€¢11mo ago
You can, but you shouldn't really delete it, you should keep your migrations, but if you want to sure
ZESS
ZESSā€¢11mo ago
got it. can I dm you? I need few help but offtopic.
Kouhai
Kouhaiā€¢11mo ago
I prefer to keep communication here šŸ˜„
ZESS
ZESSā€¢11mo ago
or can i say it here? can you give me some discord link related to dotNet? & resources to learn dotnet core mvc?
Kouhai
Kouhaiā€¢11mo ago
I don't personally know any specific links for asp.net core mvc You can check the official docs or ask over #web
ZESS
ZESSā€¢11mo ago
oh
Kouhai
Kouhaiā€¢11mo ago
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)
ZESS
ZESSā€¢11mo ago
thanks for your help ā¤ļø
Kouhai
Kouhaiā€¢11mo ago
Np Make sure to /close
Want results from more Discord servers?
Add your server
More Posts
ā” Event-Sourcing for a Duplicated Topic between Two MicroServices@Architecture Hi friends, I'm working on a project using `Microservices` architecture, I have `Autāœ… .EXE works in release but not publish?Hi, I have a WPF application, and I have made some stuff with the notification area (system tray), IRead file C#Without the Console.ReadLine(); the console closes immediately, So how can I get the code to read thā” āœ… Can anyone solve this ?ā€œInitializeComponent()ā€œ dose not exist in the current context .Can anyone solve this ? ā€œInitializeComponent()ā€œ dose not exist in the current context .ā” Quality and free project planning toolsAre there any tools you could recommend for creating and managing use cases, process diagrams, etc? āœ… P/Invoke, changing values in a struct overwrites overwrites other valuesHeyo! I'm working on a P/Invoke library for libMPV and it has a way to send it structured data insteā” OmniSharp is BrokeyI updated the C# extension on VS Code and it told me I needed to update my C# to get OnmiSharp to woā” Entity Framework, How To Join Second Table To Third Table In The First Table?Hi i want to join table city to area like picture below, but i got an error like this ```js System.āœ… XML deserialization problemCan anyone please help me sleep again.... šŸ™‚ When deserializing the following XML to the respective ā” āœ… creating an update feature in my applicationhttps://github.com/mekasu0124/Todo I've created a todo application. I want to incorporate a feature