Django Error :: IntegrityError异常值:列user_id不是唯一的

时间:2016-04-13 13:47:11

标签: django postgresql

  

IntegrityError:安装夹具'/fixtures/orders.yaml'时遇到问题:   无法加载customers.Customer(pk = 56195):列user_id不是   独特

这是我的模特

class Customer(UserenaBaseProfile):
    user = models.OneToOneField (User, unique=True)

我已经使用django fixture命令生成了灯具并运行了测试用例,当使用以下命令运行时

./manage.py test orders.tests.FixturesTestFixturesTest

我收到以下错误,

Creating test database for alias 'default'...
*************
(<Customer: AnonymousUser>, True)
****************
Checking permissions: (['Can view profile', 'Can change profile', 'Can delete profile'], [], [])
*************
(<Customer: jeffrey.gulan>, True)
****************
Checking permissions: ([], [<User: jeffrey.gulan>, <User: jeffrey.gulan>, <User: jeffrey.gulan>, <User: jeffrey.gulan>, <User: jeffrey.gulan>], [])
E
======================================================================
ERROR: setUpClass (orders.tests.FixturesTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Desktop/env_app/local/lib/python2.7/site-packages/django/test/testcases.py", line 952, in setUpClass
    'database': db_name,
  File "/Desktop/env_app/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
    return command.execute(*args, **defaults)
return self.cursor.execute(sql, params)
  File "/Desktop/env_app/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 318, in execute
    return Database.Cursor.execute(self, query, params)

IntegrityError: Problem installing fixture  
    '/Desktop/env_app/projectname/apps/orders/fixtures/orders.yaml':
    Could not load customers.Customer(pk=56195): column user_id is not unique

我也试过以下链接,

  

column user_id is not unique, with Django UserProfiles

     

Problems with column user_id is not unique

但我没有得到适当的解决方案。

如果我能得到一些帮助,那真是太好了!提前致谢

0 个答案:

没有答案