python-2.7 - 无法设置neo4jDjango图形数据库: object has no attribute 'db_type'

标签 python-2.7 django-models neo4j neo4django

我正在启动一个项目,但在执行时不断收到此错误

manage.py sql *ApplicationName*

回溯如下:

  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 304, in handle
    app_output = self.handle_app(app, **options)
  File "/usr/lib/python2.7/site-packages/django/core/management/commands/sql.py", line 19, in handle_app
    return u'\n'.join(sql_create(app, self.style, connections[options.get('database')])).encode('utf-8')
  File "/usr/lib/python2.7/site-packages/django/core/management/sql.py", line 31, in sql_create
    output, references = connection.creation.sql_create_model(model, style, known_models)
  File "/usr/lib/python2.7/site-packages/django/db/backends/creation.py", line 44, in sql_create_model
    col_type = f.db_type(connection=self.connection)
  File "/usr/lib/python2.7/site-packages/neo4django/utils.py", line 161, in __getattr__
    return getattr(super(AttrRouter, self), name)
AttributeError: 'super' object has no attribute 'db_type'

在多次尝试解决问题之后,该代码几乎是教程的一个简单示例。

settings.py 也应该是正确的,因为它们是从 neo4Django 教程复制的。

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', 
        'NAME': 'Database.db',  
    }
}

NEO4J_DATABASES = {
    'default' : {
        'HOST':'localhost',
        'PORT':7474,
        'ENDPOINT':'/db/data'
    }
}
DATABASE_ROUTERS = ['neo4django.utils.Neo4djangoIntegrationRouter']

Neo4j 服务器正在运行,并且在 sqllite 和 mysql 数据库中一切正常,因此问题一定出在 neo4j 或 neo4django 方面。当不在域中使用 neo4Django 模型时,事情也可以工作。

模型如下所示:

from neo4django.db import models

    class Person(models.NodeModel):
        name = models.StringProperty()
        age = models.IntegerProperty()
        friends = models.Relationship('self',rel_type='friends_with')

最佳答案

manage.py sql appname 命令(从 django 文档复制)

Prints the CREATE TABLE SQL statements for the given app name(s).

因此,如果您要使用 NEo4j 而不是 MySQLSQLite,则无需获取 CREATE TABLE SQL 语句。除此之外,您可能希望更好地运行 syncdb 命令,但您再次使用的不是关系数据库,而是 Neo4j,因此您不需要运行这两个命令.

您应该在 settings.pyDATABASES 声明中包含数据库的唯一原因只是因为,如果不这样做,就会出现 ImproperlyConfigured 将引发错误。

所以简单的答案是错误是正确的,只是不要运行任何关系数据库相关的 django 命令。

还有一点提示,不要使用 pypi 包,而使用 github 版本 https://github.com/scholrly/neo4django (pip install -e git+https://github.com/scholrly/neo4django/#egg=neo4django)

关于python-2.7 - 无法设置neo4jDjango图形数据库: object has no attribute 'db_type' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19717640/

相关文章:

python - 按 pandas 中的日期字符串排序 - Python 2.7

与未知数量参数相交的 Pythonic 方法

java - 通过java检索neo4j节点数据时出错

python - 在 "if"语句的返回元组中使用 bool 值?

python - 导入错误 : No module named PyQt5 - OSX Mavericks

python - 如何过滤通用外键?

python - Django post请求数据

Neo4j - 如何设置用户名和密码

neo4j - Neo4j 3.2.3中对象缓存的实现

python - 用常规属性覆盖描述符