Inspectdb错误django

时间:2016-10-04 19:46:33

标签: python django postgresql

我有postgresql db。我想通过命令

从db进行反向生成
python3 manage.py inspectdb > models/models.py

一切都很好,但我需要自定义身份验证。我从AbstractBaseUser扩展,并尝试重新考虑,因为我是改变字段。然后,我在db中查找,我看到django添加了一磅表,我无法重新检查我的数据库。错误:

python3 manage.py inspectdb > models/models.py

  super(ForeignObject, self).contribute_to_class(cls, name, private_only=private_only, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 314, in contribute_to_class
    lazy_related_operation(resolve_related_class, cls, self.remote_field.model, field=self)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 81, in lazy_related_operation
    return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 79, in <genexpr>
    model_keys = (make_model_tuple(m) for m in models)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/utils.py", line 23, in make_model_tuple
    "must be of the form 'app_label.ModelName'." % model
ValueError: Invalid model reference 'models.model.Account'. String model references must be of the form 'app_label.ModelName'.
artem@artem-debian:/usr/finstatement/project$ python3 manage.py inspectdb > models/models.py
ERROR OH NO
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/utils.py", line 14, in make_model_tuple
    app_label, model_name = model.split(".")
ValueError: too many values to unpack (expected 2)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 341, in execute
    django.setup()
  File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/local/lib/python3.4/dist-packages/django/apps/config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/models.py", line 37, in <module>
    class LogEntry(models.Model):
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py", line 157, in __new__
    new_class.add_to_class(obj_name, obj)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py", line 316, in add_to_class
    value.contribute_to_class(cls, name)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 700, in contribute_to_class
    super(ForeignObject, self).contribute_to_class(cls, name, private_only=private_only, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 314, in contribute_to_class
    lazy_related_operation(resolve_related_class, cls, self.remote_field.model, field=self)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 81, in lazy_related_operation
    return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 79, in <genexpr>
    model_keys = (make_model_tuple(m) for m in models)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/utils.py", line 23, in make_model_tuple
    "must be of the form 'app_label.ModelName'." % model
ValueError: Invalid model reference 'models.model.Account'. String model references must be of the form 'app_label.ModelName'.

它从models / models.py中删除所有模型

我现在有转储,但是我可以找到比重新创建数据库更好的解决方案吗?

1 个答案:

答案 0 :(得分:0)

好的,我找到了解决方案。需要从manage.py中删除

AUTH_USER_MODEL = 'models.models.Account'