django dumpdata空数组

编程入门 行业动态 更新时间:2024-10-10 09:24:45
本文介绍了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空数组

本文发布于:2023-10-27 23:56:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   django   dumpdata

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!