PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 14, 2022

[FIXED] How do I transfer test database to product database

 April 14, 2022     django, migration, python     No comments   

Issue

I'm working on an Django project, and building and testing with a database on GCP. Its full of test data and kind of a mess.

Now I want to release the app with a new and fresh another database.

How do I migrate to the new database? with all those migrations/ folder?

I don't want to delete the folder cause the development might continue.

Data do not need to be preserved. It's test data only.

Django version is 2.2; Python 3.7

Thank you.

========= update

After changing the settings.py, python manage.py makemigrations says no changes detected.

Then I did python manage.py migrate, and now it complains about relation does not exist.

=============== update2

The problem seems to be that, I had a table name Customer, and I changed it to 'Client'. Now it's complaining about "psycopg2.errors.UndefinedTable: relation "app_customer" does not exist".

How can I fix it, maybe without deleting all files in migrations/?

================ update final

After eliminating all possibilities, I have found out that the "new" database is not new at all. I migrated on that database some months ago.

Now I created a fresh new one and migrate worked like a charm.

Again, thank you all for your suggestions.


Solution

The migration folder is your friend. No need to delete it. You can flatten migrations if you feel the migration folder is getting too large with many migration files, but you don't need to.

If you plan to use a new database in GCP, just change the settings.py file, which is typically located in the project_name/project_name/ folder. Locate the DATABASES section to reflect the new database credentials.

Once your app is pointing at the new database, run python manage.py migrate. This will build the database schema with the necessary tables to start populating the new database.



Answered By - ja408
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing