Changing Django database backend from MySql to PostgreSQL

前端 未结 1 2041
慢半拍i
慢半拍i 2021-02-06 15:41

I use Django 1.2 and 1.3 and MySql backends.

Once in while a get an error message when migrating my MySql database with South:

! Error found during real          


        
相关标签:
1条回答
  • 2021-02-06 16:01

    I got tired of seeing this error using South and yes, switching to PostgreSQL has banished it!

    The mysql2postgres app, written in Ruby, suggested in comments above didn't work for me (it would run, output some details to screen but not copy any rows of data, for me). Not sure why. But gladly there's a Python rewrite of it that worked flawlessly (for me, eventually):
    http://pypi.python.org/pypi/py-mysql2pgsql

    The only gotcha I found was:

    Initially I thought it would be safest to set up the tables in the PostgreSQL db via a syncdb and then migrate the data only. I tried this, but the tables are migrated across in alphabetical order and this violates the foreign key constraints for some tables (rows relate to rows in tables not yet imported).

    I next tried a structure+data migration. This migrated fine, but I encountered some problems in Django afterwards, especially the admin site. It seemed like the migration script had created some different table constraints from what Django would have.

    I solved this by hacking the mysql2pgsql script to respect the order of tables given in the yaml config only_tables property... and then doing a syncdb + data-only migration. By trial and error I shuffled around the ordering of the tables for my migration until they all imported successfully.

    UPDATE:
    My pull request for the hack described above got accepted so you can do this now from the main version:
    https://github.com/philipsoutham/py-mysql2pgsql

    0 讨论(0)
提交回复
热议问题