How to migrate Django site from MySQL database to Postgres?

50 views
Skip to first unread message

Ram

unread,
Nov 23, 2019, 1:23:22 PM11/23/19
to django...@googlegroups.com
Hi,

We have our Django based website running in our local windows box with MySQL database. We plan to deploy our site on Ubuntu, Postgress, Gunicorn and Nginx stack server. I'm looking for a way to achieve this even with the manual intervention? I appreciate if someone can point me the right direction with appropriate documentation.

Thank,
~Ram

carlos

unread,
Nov 23, 2019, 6:02:14 PM11/23/19
to django...@googlegroups.com

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BOi5F1mHwkiidgcUgFJDR0e9MGbJj%2BJTZWfKgVjXkS-uN9kEw%40mail.gmail.com.


--
att.
Carlos Rocha

Ram

unread,
Nov 23, 2019, 6:32:48 PM11/23/19
to django...@googlegroups.com
Hello Carlos,

The steps looks promising. We will try it and let you know.

Our dB is originally from MySQL configured for PHP based website and later on we moved to Django project development. Now we planned to migrate the site to Postgres database running on Ubuntu for Django project.

Thank you very much.,
~Ram

Ram

unread,
Nov 23, 2019, 10:43:05 PM11/23/19
to django...@googlegroups.com
Hi Carlos,

If you get to see my email, could you review my plan and let me know whether my plan works for migration.

1. I have setup new Ubuntu 18.04 server in Digital Ocean droplet
2. Installed Postgress, Django with default settings and empty site, which means I did not bring/copy over the my Django project files yet
3. My next step is to copy over all the Django project files which are located in my developer's localhost
4. Once the files are copied to project folder in this new server I will have to run following commands, but I will not run these because old and new sites have same database software.
4.1.    (virtual env) ~/myprojectdir/manage.py makemigrations
4.2. (virtual env) ~/myprojectdir/manage.py migrate
4.3. (virtual env) ~/myprojectdir/manage.py collectstatic

5. So I want to start with your steps pointed in your blog since I have to start with an empty Postgres database. I'm not sure whether this will work or not.
6. Hopefully if all the commands are successful, I will run the above commands.

Please let me know if my plan generally would work? I know you don't have complete picture, but I'm wondering if you have any thoughts about my use case?

Thanks,
~Ram



Mohammad yunus

unread,
Nov 23, 2019, 11:13:51 PM11/23/19
to django...@googlegroups.com
Is this "migration" command will work for all type of databases or just only for sqllite3?

carlos

unread,
Nov 25, 2019, 2:54:02 PM11/25/19
to django...@googlegroups.com
i thing is good your plan copy your files local to server
then dumpdata in local database and copy to server and last you loaddata in your server

cheers



--
att.
Carlos Rocha

Ram

unread,
Nov 25, 2019, 3:59:06 PM11/25/19
to django...@googlegroups.com
Hi Carlos,

I see there is a typo in my previous steps which could have mislead you. Basically old and new sites are different databases. Old site is running remotely in local host on our Developer's machine with MySQL dB. Now I've setup new hosting server with Postgres database (empty site so far) in a Digital Ocean's droplet ( Ubuntu 18.04 OS).  So what I'm planning now is I will not run these commands in new server's virtual environment

4.1.    (virtual env) ~/myprojectdir/manage.py makemigrations
4.2. (virtual env) ~/myprojectdir/manage.py migrate
4.3. (virtual env) ~/myprojectdir/manage.py collectstatic

Before running the above, I will run all 'Migrating a Django app from MySQL to PostgreSQL' steps documented in your blog first and then proceed with the above commands in my server virtual environment.

I believe I've to run your steps in virtual environment only right?

Thanks,
~Ram


carlos

unread,
Nov 25, 2019, 4:53:06 PM11/25/19
to django...@googlegroups.com
1. Install your application on the server first, if you have media files, then copy them from your localhost to the server
2. Do the dumpdata from your local in .json, then copy that json to your server
3. Once on the server just load that json with the loaddata command.



--
att.
Carlos Rocha
Reply all
Reply to author
Forward
0 new messages