我使用的是django1.10,python3.4。当第一次尝试使用迁移时(Project是django1.6 python2.7),我收到以下错误:
(venv) ruben@erd959:~/Projects/prot-zboss/zboss$ python manage.py makemigrations utils
Traceback (most recent call last):
File "manage.py", line 8, in <module>
execute_from_command_line(sys.argv)
File "/home/nfs/ruben/Projects/prot-zboss/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/nfs/ruben/Projects/prot-zboss/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/nfs/ruben/Projects/prot-zboss/venv/lib/python3.4/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/nfs/ruben/Projects/prot-zboss/venv/lib/python3.4/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/nfs/ruben/Projects/prot-zboss/venv/lib/python3.4/site-packages/django/core/management/commands/makemigrations.py", line 106, in handle
loader.check_consistent_history(connection)
File "/home/nfs/ruben/Projects/prot-zboss/venv/lib/python3.4/site-packages/django/db/migrations/loader.py", line 276, in check_consistent_history
applied = recorder.applied_migrations()
File "/home/nfs/ruben/Projects/prot-zboss/venv/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/home/nfs/ruben/Projects/prot-zboss/venv/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
AttributeError: 'DatabaseWrapper' object has no attribute 'introspection'
看起来与数据库的关系并不好。好吧,似乎如果我删除DATABASE_ROUTERS,它再次工作,但我需要为我的LDAP功能。
DATABASES = {
'default': {
#'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'prot', # Or path to database file if using sqlite3.
'USER': 'prot', # Not used with sqlite3.
'PASSWORD': '1234', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '5432', # Set to empty string for default. Not used with sqlite3.
},
'ldap': {
'ENGINE': 'ldapdb.backends.ldap',
'NAME': 'ldap://192.168.1.39/',
}
}
DATABASE_ROUTERS = ['ldapdb.router.Router']
这是&#34; ldapdb.router.Router&#34;的代码:
def is_ldap_model(model):
# FIXME: there is probably a better check than testing 'base_dn'
return hasattr(model, 'base_dn')
class Router(object):
"""
A router to point database operations on LDAP models to the LDAP
database.
NOTE: if you have more than one LDAP database, you will need to
write your own router.
"""
def __init__(self):
"Find the name of the LDAP database"
from django.conf import settings
self.ldap_alias = None
for alias, settings_dict in settings.DATABASES.items():
if settings_dict['ENGINE'] == 'ldapdb.backends.ldap':
self.ldap_alias = alias
break
def allow_migrate(self, db, app_label, model_name=None, **hints):
if 'model' in hints and is_ldap_model(hints['model']):
return False
return None
def db_for_read(self, model, **hints):
"Point all operations on LDAP models to the LDAP database"
if is_ldap_model(model):
return self.ldap_alias
return None
def db_for_write(self, model, **hints):
"Point all operations on LDAP models to the LDAP database"
if is_ldap_model(model):
return self.ldap_alias
return None