Python 使用django csvimport的项目的迁移错误

Python 使用django csvimport的项目的迁移错误,python,django,python-3.x,Python,Django,Python 3.x,我无法将Django 1.11应用程序移动到生产环境 还有一个问题看起来与此类似,但我无法使评论中建议的答案按预期工作: 如果我注释掉settings.py中的代码以删除django csvimport库中的内容,如下所示: INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.session

我无法将Django 1.11应用程序移动到生产环境

还有一个问题看起来与此类似,但我无法使评论中建议的答案按预期工作:

如果我注释掉settings.py中的代码以删除django csvimport库中的内容,如下所示:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
   # 'csvimport.app.CSVImportConf',
    'custom_app_name',

]
然后我的迁移工作正常,应用程序运行(sans csvimport应用程序)。然后,如果我将csvimport应用程序行重新注释并运行迁移,它们将失败,原因如下:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, csvimport, sessions, custom_app_name
Running migrations:
  Applying csvimport.0002_test_models...Traceback (most recent call last):
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: syntax error at or near "csvtests_country"
LINE 1: ...CONSTRAINT "csvtests_item_country_id_5f8b06b9_fk_"csvtests_c...
                                                             ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 93, in __exit__
    self.execute(sql)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 120, in execute
    cursor.execute(sql, params)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/utils.py", line 80, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: syntax error at or near "csvtests_country"
LINE 1: ...CONSTRAINT "csvtests_item_country_id_5f8b06b9_fk_"csvtests_c...
要执行的操作:
应用所有迁移:admin、auth、contenttypes、csvimport、sessions、custom_app_name
运行迁移:
应用csvimport.0002_测试_模型…回溯(最近一次调用):
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/db/backends/utils.py”,第65行,执行
返回self.cursor.execute(sql,params)
psycopg2.ProgrammingError:位于或接近“csvtests_country”的语法错误
第1行:…约束“csvtests_item_country_id_5f8b06b9_fk_fk_”csvtests_c。。。
^
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“manage.py”,第22行,在
从命令行(sys.argv)执行命令
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/core/management/_init__.py”,第364行,从命令行执行
utility.execute()
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/core/management/_init__.py”,执行中第356行
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/home/www-root/envs/django_-env_1/lib/python3.4/site-packages/django/core/management/base.py”,第283行,从_argv运行
self.execute(*args,**cmd_选项)
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/core/management/base.py”,第330行,执行
输出=self.handle(*args,**选项)
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/core/management/commands/migrate.py”,第204行,在handle中
假首字母=假首字母,
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/db/migrations/executor.py”,第115行,在migrate中
状态=self.\u迁移\u所有\u转发(状态,计划,完整计划,假=假,假首字母=假首字母)
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/db/migrations/executor.py”,第145行,在“全部迁移”中
state=self.apply\u迁移(state,migration,false=false,false\u initial=false\u initial)
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/db/migrations/executor.py”,第244行,在apply_migration中
state=migration.apply(状态,模式编辑器)
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/db/backends/base/schema.py”,第93行,在退出时__
self.execute(sql)
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/db/backends/base/schema.py”,第120行,在execute中
cursor.execute(sql,params)
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/db/backends/utils.py”,第80行,执行
返回super(CursorDebugWrapper,self).execute(sql,params)
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/db/backends/utils.py”,第65行,执行
返回self.cursor.execute(sql,params)
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/db/utils.py”,第94行,在退出时__
6.重新播放(dj_exc_类型、dj_exc_值、回溯)
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/utils/six.py”,第685行
通过_回溯(tb)提升值
文件“/home/www root/envs/django_env_1/lib/python3.4/site packages/django/db/backends/utils.py”,第65行,执行
返回self.cursor.execute(sql,params)
django.db.utils.ProgrammingError:位于或接近“csvtests_country”的语法错误
第1行:…约束“csvtests_item_country_id_5f8b06b9_fk_fk_”csvtests_c。。。
任何建议都会非常有用。

谢谢

因此,我能够根据堆栈跟踪错误修复此问题,该错误为:

django.db.utils.ProgrammingError: syntax error at or near 
"csvtests_country"
LINE 1: ...CONSTRAINT "csvtests_item_country_id_5f8b06b9_fk_"csvtests_c...
问题是有一段生成的代码在单引号中添加了双引号,如下所示:

 options={
                'managed': True,
                'db_table': '"csvtests_country"',
            },
要查找迁移,我转到虚拟环境的python安装:

django_env/lib/python3.4/site-packages/csvimport/migrations/
并删除了双引号,因为其他“db_table”:“sometable_name”调用都没有使用双引号。我猜这是一个bug,我将向csvimport github页面报告。如果我找到更多信息,我将发布此问题的任何更新

希望这能帮助处于类似情况的人

谢谢


更新:

我以前在csvimport github页面的问题列表中没有看到这一点。这似乎是一个已知的错误: