我正在将我的Django应用从Django 1.5.5升级到1.9,Django-cms从2.4.3升级到3.3(以及所有相应的包)。
在我消除了所有弃用函数的错误之后,现在我遇到一个我无法理解的错误:“没有名为migration的模块”
当我在虚拟环境中运行以下命令时,会出现此错误: - python manage.py runserver 并且当我运行 - python manage.py migrate 时也会出现此错误。
Traceback (most recent call last):
File "manage.py", line 20, in <module>
execute_from_command_line(sys.argv)
File "/var/www/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/var/www/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/var/www/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 195, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/var/www/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 39, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/var/www/env/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 16, in <module>
from django.db.migrations.autodetector import MigrationAutodetector
File "/var/www/env/local/lib/python2.7/site-packages/django/db/migrations/__init__.py", line 1, in <module>
from .migration import Migration, swappable_dependency # NOQA
ImportError: No module named migration
管理.py
#!/usr/bin/env python2
import os
import sys
if __name__ == "__main__":
settings_module_path = 'ais.settings.production'
########## Attempt to override settings using local settings
try:
from ais.settings.local_settings import *
# For developmentent, file will probably hold the following:
settings_module_path = 'ais.settings.development'
print "!!!manage.py settings overwritten!!!"
except ImportError:
pass
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module_path
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
migrate.sh
#!/bin/sh
echo "Starting ..."
echo ">> Deleting old migrations"
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc" -delete
# Optional
echo ">> Deleting sqlite (if exists) database"
find . -name "db.sqlite3" -delete
echo ">> Running manage.py makemigrations"
python manage.py makemigrations
echo ">> Running manage.py migrate"
python manage.py migrate
echo ">> Done"
pip uninstall django && pip install django==1.11
(或者你要升级到的任何版本)。 - YPCrumblepython -c“import django; print(django.get_version())”
。那会产生什么?然后在虚拟环境激活时检查Python版本(python --version
)。版本是多少?最后一件事,当您升级Django时,可能没有同时升级manage.py
- 确保该文件的第一行是#!/usr/bin/env python
。 - YPCrumblemanage.py
文件。 - YPCrumblemigrate.sh
仅应在'src'目录内容上运行。 - Ibrahim