私はdjangoを初めて使用し、オンラインゲームのWebサイトを作成するために使用しています。ゲームにはすでに独自の認証機能があるため、それを django のカスタム認証モデルとして使用しています。
これを入れてモデルを追加するために「アカウント」という新しいアプリを作成しました。ルーターを追加して設定で有効にすると、すべてが正常に機能し、管理サイトからログインして作業を行うことができます。
現在、TDD も学習しようとしているため、認証データベースをフィクスチャにダンプする必要があります。実行する./manage.py dumpdata account
と、空の配列が返されます。エラーやトレースバックはなく、空の配列だけです。私はできる限りそれをいじりましたが、問題が何であるかを見つけることができないようです。
関連する設定をいくつか示します。
データベース
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'censored',
'USER': 'censored',
'PASSWORD': 'censored',
'HOST': 'localhost',
'PORT': '',
},
'auth_db': {
'ENGINE': 'mysql_pymysql',
'NAME': 'censored',
'USER': 'censored',
'PASSWORD': 'censored',
'HOST': '127.0.0.1',
'PORT': '3306'
}
}
ルーター
class AccountRouter(object):
"""
A router to control all database operations on models in the
account application.
"""
def db_for_read(self, model, **hints):
"""
Attempts to read account models go to auth_db.
"""
if model._meta.app_label == 'account':
return 'auth_db'
return None
def db_for_write(self, model, **hints):
"""
Attempts to write account models go to auth_db.
"""
if model._meta.app_label == 'account':
return 'auth_db'
return None
def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the account app is involved.
"""
if obj1._meta.app_label == 'account' or \
obj2._meta.app_label == 'account':
return True
return None
def allow_syncdb(self, db, model):
"""
Make sure the account app only appears in the 'auth_db'
database.
"""
if model._meta.app_label == 'account':
return False
return None
ジャンゴの設定
DATABASE_ROUTERS = ['account.router.AccountRouter']
私は本当に何を試すべきか途方に暮れています。どんな助けやアイデアも大歓迎です。