【问题标题】:error:AttributeError: 'super' object has no attribute 'db_type' when run "python manage.py syncdb" in django错误:AttributeError:在 django 中运行“python manage.py syncdb”时,“超级”对象没有属性“db_type”
【发布时间】:2026-01-04 23:30:01
【问题描述】:

我正在做一个 django 项目,我有两个数据库“mysql”和“neo4j”。我安装 neo4django 包并更改 setting.py,如下所示:

setting.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'mylifetime',                     
        'USER': 'root',
        'PASSWORD': 'mypassword',
        'HOST': '',                      
        'PORT': '',
    }
}
NEO4J_DATABASES = {
    'default' : {
        'HOST':'localhost',
        'PORT':7474,
        'ENDPOINT':'/db/data'
    }
}

而我的模型目前只有 neo4j 模型:

models.py:

from neo4django.db import models


class User(models.NodeModel):
    ...
    #my User models ...
    ....
class Post(models.NodeModel):
    ...
    #my Post models
    ...

当我运行这个命令 python manage.py syncdb 时出现错误:

$ python ../manage.py syncdb
Creating tables ...
AttributeError: 'super' object has no attribute 'db_type'

当我只使用 MySql 模型时,我看不到错误并且表将成功创建。 我错在哪里? 谢谢

编辑: 当我写python manage.py syncdb --traceback 时,我看到如下:

Creating tables ...
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 222, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 255, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 385, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 91, in handle_noargs
    sql, references = connection.creation.sql_create_model(model, self.style, seen_models)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/creation.py", line 50, in sql_create_model
    col_type = f.db_type(connection=self.connection)
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/utils.py", line 303, in __getattr__
    return getattr(target, name)
AttributeError: 'super' object has no attribute 'db_type'

【问题讨论】:

标签: python django django-models neo4j neo4django


【解决方案1】:

使用manage.py--traceback 选项来查看您获得的异常的完整堆栈跟踪。

【讨论】:

  • 我不知道这个选项存在! +1
【解决方案2】:

in the docs 所述,如果您想针对 Neo4j 一个关系数据库运行,您需要在 settings.py 中将 neo4django.utils.Neo4djangoIntegrationRouter 添加到您的 DATABASE_ROUTERS

【讨论】: