我正在使用Postgresql处理Django 1.9,并且我遇到了不同模式中表之间关系的问题。
我面临的问题是我有一个名为product
的表,它位于名为dataflex
的模式中,另一个名为client_product_sale_stx
的表位于另一个模式中
当我尝试迁移client_product_sale_stx
和product
之间的关系时,我收到了此错误:
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_id
是client_product_sale_stx
模型/表中关系字段的名称。
product
模型/表没有关系字段。