使用 Django 将数据从 Mysql 迁移到 Postgres - 如何迁移通用表数据,而不是特定于模型的数据?
python manage.py dumpdata modelName >文件.json
。- 在 postgres 上为用户
meder
创建了一个空数据库 - 修改了 pga_hb.conf,以便
meder
可以使用该数据库 - 中的设置
- 更改了
settings.py
python Manage.pysyncdb(我没有创建su) 尝试
loaddata file.json
但它抱怨超级用户不存在或不匹配...回溯(最近一次调用最后一次): 文件“manage.py”,第 11 行,位于 执行管理器(设置) 文件“/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/init.py”,第 438 行,在execute_manager 中 实用程序.execute() 文件“/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/init.py”,第 379 行,执行中 self.fetch_command(子命令).run_from_argv(self.argv) 文件“/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/base.py”,第 191 行,在 run_from_argv 中 self.execute(*args, **options.dict) 文件“/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/base.py”,第 220 行,执行中 输出 = self.handle(*args, **选项) 文件“/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/commands/loaddata.py”,第 219 行,在句柄中 transaction.commit(使用=使用) 文件“/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/db/transaction.py”,第 199 行,提交中 连接._commit() 文件“/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/db/backends/init.py”,第 32 行,在 _commit 中 返回 self.connection.commit() psycopg2.IntegrityError:在表“bugs_bug”上插入或更新违反了外键约束“poster_id_refs_id_89e0243f” 详细信息:表“auth_user”中不存在键 (poster_id)=(1)。
我不应该syncdb吗?我应该转储通用表的数据吗?我在 MySQL 中仍然保留着完整的数据库,但希望得到任何指导。
旁注:我确实安装了south
。几天前我执行了 --initial
命令。也许我也可以使用南方?
python manage.py dumpdata modelName > file.json
.- created an empty database for a user
meder
on postgres - modified pga_hb.conf so that
meder
can use the database - changed the settings in
settings.py
- python manage.py syncdb ( I didnt create a su )
attempting to
loaddata file.json
but it complains that the superuser isn't there or doesn't match up...Traceback (most recent call last):
File "manage.py", line 11, in
execute_manager(settings)
File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/init.py", line 438, in execute_manager
utility.execute()
File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/init.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.dict)
File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", line 219, in handle
transaction.commit(using=using)
File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/db/transaction.py", line 199, in commit
connection._commit()
File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/db/backends/init.py", line 32, in _commit
return self.connection.commit()
psycopg2.IntegrityError: insert or update on table "bugs_bug" violates foreign key constraint "poster_id_refs_id_89e0243f"
DETAIL: Key (poster_id)=(1) is not present in table "auth_user".
Was I not supposed to syncdb? Was I supposed to dumpdata for the generic tables? I still have the db all intact in MySQL but would appreciate any direction.
SIDENOTE: I do have south
installed. I did the --initial
command a couple days ago. Perhaps I could use south as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须运行:
这将从所有表(模型)中转储数据。
运行 python manage.py dumpdata myapp.modelName > file.json. 只会转储应用程序 myapp 中模型 modelName 的数据。
如果您只想转储模型 modelName 的数据,您也可以尝试这样做:
这样,用户的数据也将被转储。
You have to run:
This will dump data from all tables(Models).
Running
python manage.py dumpdata myapp.modelName > file.json.
will only dump data for model modelName in app myapp.You can also try, this if you only want to dump data for model modelName:
This way data with Users will also dumped.
在这里使用
更多:
http://docs.djangoproject。 com/en/dev/ref/django-admin/#django-admin-option---natural
Use
More here:
http://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-option---natural
很久以前,在经历了痛苦的导出/导入 jsons 痛苦之后,我最终使用 https://pypi.python.org /pypi/py-mysql2pgsql
long time ago after excruciating export/import jsons pains I end up using https://pypi.python.org/pypi/py-mysql2pgsql