Here is the situation, i have a Django project in common with other developpers, each one with specific applications and Models, but we share some Models and templates.
So in my part of the project, i have Models and migrations folders.
I’ve done many changes on these Models and i’d like to migrate them in the project, but has it’s big changes i’m wondering if a simple “makemigrations”, “migrate”, will be enough.
I don’t want to break the database with a bad migration as my colleagues are working on it.
So before to try it i prefer to ask you.
Is it adequate for you if i first clean my models from all objects, then reset all migrations by deleting the migrations folders of my apps, and finally do a makemigrations MyApp and migrate MyApp.
Or do i have to also pass by the database and delete manually my tables before to recreate them with django ?
Thank you !
Migrations within different systems generally gives conflicts, if your other colleagues are working on completely different apps within django project than your migration might not give error as such but there are always chances that your migrations folder might gives conflict.
Another way If you using GitHub or git-lab and your DB (except db.sqlite3) is locally setup for each system than you can put your migrations and pycahe to git ignore and then if anyone changes anything within models just take pull and make-migrations and migrate within your system.
There are always different case scenarios, if someone would give more insights than it might help me to know the different possibilities.
Thank you for your answer,
The project is not connected to Github or Git Lab, the database is in MySql an fully based in a common Linux server, as all of the the Django folders.
So, as my objects and Tables are actually just to test, I’ll be tempted to delete my migration files, delete the pychache ( for that matter), delete my tables manually (DROP TABLE MyTable) to make sure they won’t raise errors, and just redo the classic makemigrations/migrate as it was the first time.
I’m asking if it’s the best way because it looks a bit drastic and I’m not sure I’m 100% familiar with how migrations work in Django.
you can do it by looking at the model.py file in your Django project. each model in the field will be represented by a class. you can do this by running the following command in your project directory
python manage.py mokemigrations --empty<app_name>. Then replace <app_name> with the name of app that contain the models you want to reset…
thank you for your answer, i didn’t know the makemigration --empty function. From what i see in the doc, it create an empty migration folder, so i guess i can then do a classic makemigration to recreate my models with the new ones.
But about the real tables in my database, they won’t be deleted or cleaned, so when i’ll redo the makemigration don’t you think they will be a conflict ? Not from the migrations folders, but from the tables attributes, their types, the existing objects, as the Django known migration will be tottaly different from the existing data in my database. Or Django will just replace it with my new models attributes ?