django.db.utils.ProgrammingError: (1146, "Table 'db_gold.user_ip_info' doesn't exist") RuntimeError: Model class scanhosts.models.HostLoginInfo doesn't declare an explicit app_label and isn't in an a


Error Msg

創建了一個apps的目錄將所有app放入apps文件中, 將apps路徑加入sys.path中:
sys.insert(0, os.path.join(BASE_DIR, "apps"))

未改前: RuntimeError: Model
class scanhosts.models.HostLoginInfo doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS. 安裝app到install_apps中后, 變成: django.db.utils.ProgrammingError: (1146, "Table 'db_gold.user_ip_info' doesn't exist")

原因及解決:

  1. 沒有安裝apps, 在setting.py中安裝app

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    "users",
    "scanhosts",
    "details"
]

  2. 安裝app后, 所有用到app中的模塊導入必須使用app.模塊名,  不能使用上級目錄apps

只能使用:
from scanhosts.utils import login_ssh_do
from scanhosts.models import * 不能使用:
from apps.scanhosts.utils import login_ssh_do
from apps.scanhosts.models import *

  3. 如果無法遷移, 可指定遷移model來遷移:

python manage.py makemigrations users scanhosts details
python manage.py migrate

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM