如何解决“表""auth_permission"问题?已经存在"在两个Django项目之间共享数据库时出错 [英] How to solve "table "auth_permission" already exists" error when the database is shared among two Django projects

查看:64
本文介绍了如何解决“表""auth_permission"问题?已经存在"在两个Django项目之间共享数据库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题,我学习了如何使两个Django项目使用相同的数据库.我有:

in this question I learned how to make two Django projects use the same database. I have:

projects
  project_1
    settings.py
    ...
  project_2
    settings.py
    ...

# project_1/settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(PROJECT_ROOT, 'development.db'),
    },
}


# project_2/settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(
            os.path.dirname(os.path.dirname(PROJECT_ROOT)),
            'project_1',
            'development.db'
        ),
    },
}

project_2/中,当我运行时:

python manage.py syncdb

我得到:

django.db.utils.OperationalError: table "auth_permission" already exists

我想发生这种情况是因为python尝试添加共享数据库中已经存在的 project_2 表失败.

I guess this happens because python fails in trying to add project_2 tables that already exists in the shared db.

如何仅将公用数据库中不存在的 project_2 表添加到共享数据库?

How can I add to the shared db only those project_2 tables not already existing in the common database?

告诉project_2/使用project_1/db后,我运行 syncdb 并获取现有表错误.我没有迁移文件.同步之前,我应该运行其他命令吗?

After telling project_2/ to use project_1/ db, I run the syncdb and get the existing table error. I do not have a migration file. Shall I run a different command before syncing?

推荐答案

针对project_2/的Django 1.8.15.我刚刚检查了project_1/django版本,它是1.6.我确信这两个项目都使用相同的Django版本.这是主要问题吗?

Django 1.8.15 for project_2/. I've just checked project_1/ django version and it is 1.6. I was convinced that both projects where using the same django version.. Is this the main problem?

是的.因为django 1.6和django 1.8使用不同的 syncdb 命令.1.8中的 syncdb migrate ,因此,当您在1.8中执行 syncdb 时,您将应用迁移,而不仅仅是创建表.使用相同的Django版本,应该解决问题.

Yes. Because django 1.6 and django 1.8 use different syncdb commands. syncdb in 1.8 is migrate, so when you do syncdb in 1.8 you are applying migrations, not just creating tables. Use same django version and problem should be solved.

这篇关于如何解决“表""auth_permission"问题?已经存在"在两个Django项目之间共享数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆