django dumpdata空数组 [英] django dumpdata empty array

查看:59
本文介绍了django dumpdata空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对django并不陌生,我正在用它来建立一个在线游戏网站。游戏已经拥有自己的身份验证内容,因此我将其用作django的自定义身份验证模型。

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.

现在我也在尝试学习TDD,所以我需要将auth数据库转储到Fixture。
当我运行 ./ manage.py dumpdata帐户时,我得到了一个空数组。迄今为止没有任何错误或任何追溯,只是一个空数组。我尽了最大的努力来弄弄它,但似乎找不到问题所在。

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.

以下是一些相关设置。

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


Django设置


DATABASE_ROUTERS = ['account.router.AccountRouter']

对于尝试什么我真的很茫然,感谢任何帮助或想法。

I am really at a loss for what to try, any help or ideas are appreciated.

推荐答案

我也有同样的问题,您需要指定正确的数据库。例如,给定您的代码:

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

这篇关于django dumpdata空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆