How to migrate old database into new database using python script

101 views
Skip to first unread message

Mohammad Aqib

unread,
Oct 11, 2018, 12:01:14 PM10/11/18
to django...@googlegroups.com
Hi All,
I have a task to migrate all data into a new database using "backup.sql" file.
How to write a Python script to do this task.

Thanks

Mohammad Shareef M

unread,
Oct 11, 2018, 12:03:44 PM10/11/18
to django...@googlegroups.com
Create new database and Restore the backup file

Thanks & Regards,
Mahammad Shareef M


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOh93ncV9awh9Y6GCC72FCY4XUO2eOSBWpB-TKH_RRmOk_4vZA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ryan Gedwill

unread,
Oct 11, 2018, 4:33:58 PM10/11/18
to django...@googlegroups.com
Depending on the SQL distribution you're using, there should be a couple tools to do this without python using a CLI command or a basic SQL script.

If you need to do it in python, use a basic python library (again, depends on your sql distribution) to connect to your database and execute the SQL command to execute the file.

I only remember how to do this in postgres specifically, but you happen to be using postgres as well, I can help further.

Mohammad Aqib

unread,
Oct 11, 2018, 4:42:07 PM10/11/18
to django...@googlegroups.com
I know CLI commands to backup db and restore into another but in this case CLI would not work because previous db tables is different from new db tables.

So, I have backup.sql file and need to read this file and dump the values into new db

Or another option I know, is to connect server db and execute queries one by one. Which is very lengthy and horrible process.

Is any other way to do this?

carlos

unread,
Oct 12, 2018, 1:13:14 AM10/12/18
to django...@googlegroups.com
Maybe you use dumpdata in json and then modify the table name, in editor code, then loaddata in new db

Cheers


For more options, visit https://groups.google.com/d/optout.


--
att.
Carlos Rocha

Joel Mathew

unread,
Oct 12, 2018, 1:54:19 AM10/12/18
to django...@googlegroups.com
Just import the old ones from sql and then modify the tables.
Sincerely yours,

Dr Joel G Mathew



Reply all
Reply to author
Forward
0 new messages