0

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 3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I run exactly the same commands as shown above by you. Also, it shows me the new module that I added in the Console window. But when I open the admin website, I do not see the new added module there. Am I missing something here? I can provide you the log trace of the commands that I executed.
The commands that I run are: 1. python manage.py makemigrations splash. Output: Migrations for 'splash': 0001_initial.py: - Create model Splash
2. python manage.py migrate splash. Output: Operations to perform: Apply all migrations: splash Running migrations: No migrations to apply.
0

You shouldn't be making changes directly to the database. That is what migrations are for.

7 Comments

Why this is so complex? Isn't there an easy way to complete this? e.g. Just replace the old Database schema with the new one. The server is hosted on DigitalOcean website.
What on earth do you mean, complex? Migrations are for making it simple. This is the easy way. And you can't just "replace" a database schema, what would happen to all the data?
So if I have introduced a new section in the admin panel and created a new model, what according you the sample migration commands will look like? Can you just share any sample commands? That would be much helpful to get me started. Thanks
@YuDroid Django tutorial have everything you want.
@YuDroid This is a process and you should follow the process as per migrations is Concern. :D
|
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.