簡體   English   中英

使用django-csvimport的項目的遷移錯誤

[英]migration errors for project using django-csvimport

我在將Django 1.11應用程序投入生產時遇到了麻煩。

還有一個類似問題的問題,但我無法按需使用注釋中建議的答案: 應用程序csvimport的Django導入錯誤

如果我注釋掉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',

]

然后我的遷移工作正常,並且該應用程序運行(沒有csvimport應用程序)。 然后,如果我重新注釋csvimport APP行並運行遷移,則它們將失敗並顯示以下內容:

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...

任何建議都將非常有幫助。
謝謝!

因此,我能夠根據讀取的堆棧跟蹤錯誤來解決此問題:

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'調用均未使用雙引號的事實刪除雙引號。 我猜這是我將向csvimport github頁面報告的錯誤。 如果我找到更多信息,我將發布對此問題的任何更新。

希望這可以幫助處於類似情況的人。

謝謝!


更新:

我以前在csvimport github頁面的問題列表中沒有看到此消息。 它似乎是一個已知的錯誤: https : //github.com/edcrewe/django-csvimport/issues/77

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM