I have been given a new project with website running on Django back-end. This uses the PostgreSQL database. The changes I have completed on my local system. My client has given me a live remote machine with proper FTP, SSH and database access. He also created a database dump file and provided it to me. I have completed the necessary code and database changes. But now I don't know how to sync these database changes back to the server. I am fairly new to Django and PostgreSQL stuff and don't know how to accomplish this task. Your help will be much appreciated in this. Thanks
3 Answers
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.
3 Comments
python manage.py makemigrations splash. Output: Migrations for 'splash': 0001_initial.py: - Create model Splashpython manage.py migrate splash. Output: Operations to perform: Apply all migrations: splash Running migrations: No migrations to apply.You shouldn't be making changes directly to the database. That is what migrations are for.