使用postgresql在django中的不同模式中的表之间的关系

时间:2017-01-02 17:54:14

标签: python django postgresql python-2.7 schema

我正在使用Postgresql处理Django 1.9,并且我遇到了不同模式中表之间关系的问题。

我面临的问题是我有一个名为product的表,它位于名为dataflex的模式中,另一个名为client_product_sale_stx的表位于另一个模式中

当我尝试迁移client_product_sale_stxproduct之间的关系时,我收到了此错误:

Applying armazem.0077_clientproductsalestx_setor_id...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 90, in __exit__
self.execute(sql)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 110, in execute
cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: ERRO:  syntax error at or near "dataflex"
LINE 1: ...CONSTRAINT "client_product_setor_id_52aad07a_fk_"dataflex"....

在尝试找出解决此问题的解决方案之后,我尝试将模式的名称更改为仅df而不是dataflex,并且它运行良好。

我也尝试减少表的名称,它就像我减少了模式的名称大小一样,所以这很可能是大约束名称的问题。

对于不同模式之间的关系,djando和postgresql大名是否存在同样的问题?

还有其他方法可以解决吗?因为我可能需要有更大名称的表,而且我不能再减少模式的名称大小。

setor_idclient_product_sale_stx模型/表中关系字段的名称。 product模型/表没有关系字段。

0 个答案:

没有答案