Issue
I am fairly new to django and I am using it to make a website for an online game. The game already has it's own auth stuff so I am using that as a custom auth model for django.
I created a new app called 'account' to put this stuff in and added the models. I added the router and enabled it in the settings and everything works good, I can log in from the admin site and do stuff.
Now I am also trying to learn TDD, so I need to dump the auth database to a fixture.
When I run ./manage.py dumpdata account
i get an empty array back. There aren't any errors or any trace back what so ever, just an empty array. I've fiddled with it the best I can but I can't seem to find what the issue is.
Here are some relevant settings.
Database
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'
}
}
Router
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
Django Settings
DATABASE_ROUTERS = ['account.router.AccountRouter']
I am really at a loss for what to try, any help or ideas are appreciated.
Solution
I also had the same issue, you need to specify the correct database. For example, given your code:
$ ./manage.py dumpdata --database=auth_db account
Answered By - Márcio
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.