Can someone explain database migration in Django? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone explain database migration in Django?

I'm learning about Django currently. I know database migration means transferring data from one place to another. Ok, let's just say I don't get it . Why is it needed?

21st Oct 2021, 7:44 AM
Richard
Richard - avatar
3 Answers
+ 3
This is not exactly. Migrations are features that enables you change the data model and deploy that changes into your database schema. Here some documentations. django migrations: - https://docs.djangoproject.com/en/3.2/topics/migrations/ EF - https://entityframework.net/migration - "So in human readable what it means?" Example: You have a model (Employee class) with 5 fields, so in your DB (database) will be a table Employee with 5 columns. Tomorrow your boss ask to add a new column in that db , what's going next? You add a field in employee model, now with 6 fields, but in your db the table employee still have 5 columns. So, you make a migrations that add that field to your db schema. Then Employee table will have 6 column. (This is just a simple and stupid example, you can make more things than just adding a column with migrations) BUT BE CAREFUL. You need to be very careful with migrations, It's possibile to "erase" the entire data in that table that you changed adding the new column.. yee, it was a bad day for me eheh, of course I discovered it after the migration. There are a lot of documentations online and people who explains better than me. Hope i helped you instead making confusion.
21st Oct 2021, 10:02 AM
Sudo-Ale
Sudo-Ale - avatar
0
Thanks, Sudo- Ale , but the link is not working though
21st Oct 2021, 3:47 PM
Richard
Richard - avatar
0
Just search "migrations db django" on your browser and there you go.
21st Oct 2021, 3:50 PM
Sudo-Ale
Sudo-Ale - avatar