2016-11-13 204 views
0

我將數據庫從mysql更改爲postgre。由於數據庫中沒有數據,我只是刪除了每個應用程序的遷移文件夾。當我跑makemigrations事後,雖然,我得到這個錯誤:刪除Django遷移

/theme/admin.py", line 2, in <module> 
from models import theme, theme_file 
ImportError: No module named 'models' 

之前的所有工作得很好,沒有什麼比被清潔的遷移文件夾以外的代碼改變。

任何想法?

/Users/jl/.virtualenvs/bolts3/bin/python /Users/jl/Desktop/Bolts/manage.py runserver 8000 
    Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x108e15ae8> 
    Traceback (most recent call last): 
     File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper 
     fn(*args, **kwargs) 
     File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run 
     autoreload.raise_last_exception() 
     File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception 
     six.reraise(*_exception) 
     File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise 
     raise value.with_traceback(tb) 
     File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper 
     fn(*args, **kwargs) 
     File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/__init__.py", line 27, in setup 
     apps.populate(settings.INSTALLED_APPS) 
     File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate 
     app_config.ready() 
     File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/contrib/admin/apps.py", line 23, in ready 
     self.module.autodiscover() 
     File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover 
     autodiscover_modules('admin', register_to=site) 
     File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules 
     import_module('%s.%s' % (app_config.name, module_to_search)) 
     File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/importlib/__init__.py", line 126, in import_module 
     return _bootstrap._gcd_import(name[level:], package, level) 
     File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
     File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
     File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked 
     File "<frozen importlib._bootstrap>", line 673, in _load_unlocked 
     File "<frozen importlib._bootstrap_external>", line 662, in exec_module 
     File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 
     File "/Users/jl/Desktop/Bolts/theme/admin.py", line 2, in <module> 
     from models import theme, theme_file 
    ImportError: No module named 'models' 
+0

我老實說不知道爲什麼錯誤會在沒有任何代碼被改變的情況下發生。但是,請嘗試在/theme/admin.py文件的第2行中將'from models import'更改爲'from .models import'。 –

+0

這是我第一次嘗試。同樣的結果。 –

+1

你能告訴我們你的項目目錄樹嗎? – Enix

回答

0

只是在更改數據庫類型時刪除遷移不會解決問題。在您的settings.py文件中,您必須將默認數據庫設置更改爲指向新的PostgreSQL數據庫,並指定模式,數據庫用戶名和密碼等。也許您還沒有這樣做?

DATABASES = { 
'default': { 
    'ENGINE': 'django.db.backends.postgresql', 
    'NAME': 'mydatabase', 
    'USER': 'mydatabaseuser', 
    'PASSWORD': 'mypassword', 
    'HOST': '127.0.0.1', 
    'PORT': '5432', 
} 

}

參見:https://docs.djangoproject.com/en/1.10/ref/settings/

0

嗯它似乎像你刪除的文件__init__.py意外?

請記住,一個文件夾必須有這樣的文件是一個python模塊,當一個文件夾是一個python模塊,你可以從它導入。