0đź‘Ť
You shouldn’t be making changes directly to the database. That is what migrations are for.
1đź‘Ť
Just like Daniel Roseman said, Django migrations will be more easy to do this instead of “Just replace the old Database schema with the new one”.
Because people is easy to make mistakes, and easy to forget which field you had edit or remove.And sometimes it will cause problem when the field you create in database is a little bit different than in django model.
For instance
- In database, you set a create_time field like this datetime(6) NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
- In Django model, you set create_time = models.DateTimeField() in django model
Your project will work, but you will not notice there will be a problem when you update the record but the create_time will also been updated. It’s hard to find the bug and maintain the project.Besides, if you use docker to deploy your project, in the docker file you can just use
python manage.py makemigrations
python manage.py migrate
to make sure every database will have the same database schema.You don’t have to replace the database one by one.
- Models referring to each other – how can I most efficiently fix this issue?
- Can't activate django python environment in docker django application
0đź‘Ť
This what helped me:
I changed the database name at settings and created a new one at PGADMIN(interface for running PostgreSQL)
Then I did the two migrations: makemigrations and migrate
- Django atomically limit check and increment counter for multiple tables
- Sorted/searchable StackedInline options