使用 Django 将数据从 Mysql 迁移到 Postgres - 如何迁移通用表数据,而不是特定于模型的数据?

发布于 2024-09-25 14:29:13 字数 1817 浏览 2 评论 0原文

  1. python manage.py dumpdata modelName >文件.json
  2. 在 postgres 上为用户 meder 创建了一个空数据库
  3. 修改了 pga_hb.conf,以便 meder 可以使用该数据库
  4. 中的设置
  5. 更改了 settings.py python Manage.pysyncdb(我没有创建su)
  6. 尝试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 命令。也许我也可以使用南方?

  1. python manage.py dumpdata modelName > file.json.
  2. created an empty database for a user meder on postgres
  3. modified pga_hb.conf so that meder can use the database
  4. changed the settings in settings.py
  5. python manage.py syncdb ( I didnt create a su )
  6. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你没皮卡萌 2024-10-02 14:29:13

您必须运行:

python manage.py dumpdata > file.json.

这将从所有表(模型)中转储数据。

运行 python manage.py dumpdata myapp.modelName > file.json. 只会转储应用程序 myapp 中模型 modelName 的数据。

如果您只想转储模型 modelName 的数据,您也可以尝试这样做:

python manage.py dumpdata auth myapp.MyModel > file.json

这样,用户的数据也将被转储。

You have to run:

python manage.py dumpdata > file.json.

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:

python manage.py dumpdata auth myapp.MyModel > file.json

This way data with Users will also dumped.

我们只是彼此的过ke 2024-10-02 14:29:13

在这里使用

python manage.py dumpdata --natural > file.json.

更多:
http://docs.djangoproject。 com/en/dev/ref/django-admin/#django-admin-option---natural

Use

python manage.py dumpdata --natural > file.json.

More here:
http://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-option---natural

琴流音 2024-10-02 14:29:13

很久以前,在经历了痛苦的导出/导入 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文