迁移时自定义用户和django-registration-redux错误

时间:2021-01-07 23:18:54

I just installed django-registration-redux, added 'registration' to INSTALLED_APPS and to urls, but when migrating, I get next error:

我刚刚安装了django-registration-redux,将'registration'添加到了INSTALLED_APPS和url,但是在迁移时,我得到了下一个错误:

Synchronizing apps without migrations:
  Creating tables...
    Creating table core_brand
    Creating table core_product
    Creating table core_package
    Creating table core_consignment
    Creating table core_slider
    Creating table core_slideritems
    Creating table order_cart
    Creating table order_order
    Creating table order_orderproduct
    Creating table registration_registrationprofile
    Running deferred SQL...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py", line 179, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py", line 317, in sync_apps
    cursor.execute(statement)
  File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "C:\Python27\lib\site-packages\django\db\utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 62, in execute
    return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "login_customuser" does not exist

The problem is that I use CustomUser model. I do it in the next way: class

问题是我使用CustomUser模型。我是以下一种方式做的:上课

CustomUser(AbstractUser):
    mobile = models.CharField(max_length=20)
    address = models.CharField(max_length=100)

and in settings.py added AUTH_USER_MODEL = 'login.CustomUser' Why does this error appear? Because, after this error, I looked into database tables and login_customuser exists.

并在settings.py中添加了AUTH_USER_MODEL ='login.CustomUser'为什么会出现此错误?因为,在此错误之后,我查看了数据库表并且login_customuser存在。

1 个解决方案

#1


You say you added login.customuser. The name is different from login_customuser you mentioned elsewhere. Try that to see if it works. Aside from that, I advise you use makemigrations and migrate one after the other to have better results.

你说你添加了login.customuser。该名称与您在其他地方提到的login_customuser不同。试试看它是否有效。除此之外,我建议您使用makemigrations并逐个迁移以获得更好的结果。

#1


You say you added login.customuser. The name is different from login_customuser you mentioned elsewhere. Try that to see if it works. Aside from that, I advise you use makemigrations and migrate one after the other to have better results.

你说你添加了login.customuser。该名称与您在其他地方提到的login_customuser不同。试试看它是否有效。除此之外,我建议您使用makemigrations并逐个迁移以获得更好的结果。