How can I easily convert a Django app from mySQL to PostgreSQL?

后端 未结 7 1893
一个人的身影
一个人的身影 2021-01-31 12:04

Has anyone done this? Is it an easy process? We\'re thinking of switching over for transactions and because mysql seems to be \"crapping out\" lately.

7条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 12:12

    1. python manage.py dump.data >> data.json

    2. Create database and user in postrgesql

    3. Set your just created database in postrgesql as default database in django settings or use param --database=your_postrgesql_database next steps
    4. Run syncdb for create tables.

      python syncdb [--database=your_postrgesql_database] --noinput

    5. Create dump without data, drop all tables and load dump. Or truncate all tables (table django_content_type whith data which can be not equals your old data - it is way to many errors). At this step we need empty tables in postgresql-db.

    6. When you have empty tables in postgresql-db just load your data:

      python manage.py loaddata data.json

    And be fun!

提交回复
热议问题