簡體   English   中英

Django Heroku users_customuser 表無法遷移

[英]Django Heroku users_customuser table can't migrate

我有一個 Django 項目,我在本地開發了一段時間。 它在我的本地機器上運行良好,我使用的是自定義用戶設置,因此我的登錄身份驗證只需要電子郵件/密碼,而不是需要電子郵件/用戶名/密碼的默認 Django 用戶表。

我剛剛在 Heroku 上托管了我的項目,並且可以看到網頁 UI 加載得很好。 但是我在單擊任何鏈接時收到 Django 錯誤,並認為它與我嘗試運行時出現的問題有關

heroku run python manage.py migrate

我正在嘗試在 heroku 上運行它來設置數據庫,但是當我這樣做時,我收到一條錯誤消息:

Running python manage.py migrate on ⬢ songsweeper... up, run.1353 (Free)
Operations to perform:
  Apply all migrations: account, admin, auth, contenttypes, playlist, sessions, sites
Running migrations:
  Applying account.0001_initial...Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "users_customuser" does not exist


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 234, in handle
    fake_initial=fake_initial,
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 247, in apply_migration
    migration_recorded = True
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 110, in __exit__
    self.execute(sql)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 137, in execute
    cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 99, in execute
    return super().execute(sql, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "users_customuser" does not exist

我的項目非常大,但為了概述我在哪里定義 customuser,它出現在以下位置:

在此處輸入圖片說明

有沒有人對如何解決此遷移錯誤有任何建議? 或者它是指示性的還是其他的東西? 我網站上的“登錄”鏈接導致了一個不同的錯誤,指出“關系“django_site”不存在”,但我認為這與這個失敗的自定義用戶錯誤有關。

我目前使用默認的 sqlite3 db。

我之前遇到過和你類似的問題。 在我看來,我認為這是因為用戶應用程序中的遷移文件。 因此,您必須遷移用戶模型。

$ python manage.py makemigrations users
$ python manage.py migrate

我用上面的方法解決了這個問題。

暫無
暫無

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

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