1. 程式人生 > >django.db.utils.InternalError 1054 Unknown column 不存在程式碼中

django.db.utils.InternalError 1054 Unknown column 不存在程式碼中

解決方法請直接看結尾!!!

我本來是覺得這個問題這麼難解決,應該寫個blog一遍解決一邊記錄下各種嘗試過程,結果emmm。

我今天打算給一個點位(Point模型)新增照片(Photo模型,外來鍵Point模型)的時候,輸完p.photo_set.all()本來期待輸出<QuerySet []>(畢竟照片還沒有新增)遇到了一個特別奇怪的報錯。

>>> from routes.models import Route, Point, Photo
>>> p = Point.objects.get(id=3)
>>> p
<Point: No.3 point 3>
>>> p.photo_set.all()

django.db.utils.InternalError: (1054, "Unknown column 'routes_photo.photo_file' in 'field list'")

routes_photo是應用名_模型名,這個報錯的意思是photo_file欄位在資料庫中不存在。

但是,問題是,這個photo_file在我的程式碼裡也不存在啊!!!不信你看嘛!!!

pycharm中ctrl+shift+F全域性搜尋photo_有很多搜尋結果(在模型Photo下定義了不少欄位),但是沒有定義photo_file。

不過這個photo_file的確曾經存在的,我把photo_file改名為photo_url了。但問題是我已經更新遷移了啊,而且全域性搜尋也沒有不是嗎!也許遷移有什麼問題,簡單粗暴地刪庫刪migration檔案然後重新:

  • python manage.py makemigrations routes
  • python manage.py migrate

但是並沒有什麼用。搜了半天中文部落格,裡面都是和我完全不相關的問題,什麼最前面有個空格啊,什麼忘記migrate或者忘記makemigrations了,好不容易在部落格園裡面看到一個和我問題一樣的,大家說了以上方法樓主表示都已經做過了以後,帖子就坑了。倒是看到幾個比較靠譜的中文部落格(點選連結),但是和我的方法是一樣的,刪光重建嘛。

不喜歡上Stack overflow的原因是,我遇到的問題一般都特別低階,我也不知道怎麼描述,然後stac面的錯誤也高階,解決方法也高階,總是雲裡霧裡然後在某個同為小白的csdn裡面找到了答案。Stack裡面搜了半天,搜到一個和我。看紅色框內,也是改了欄位名然後報錯說找不到原來的欄位名(which 我倆也都沒想用它啊)。

不過這位小哥不是和我一樣修改模型然後生成遷移的,而是直接寫了遷移檔案。

解答區果然也抓住這點了,開始“delete-makemigrations-migrate三連”

我都做了這些啊可是沒有用啊.jpg 

小哥的解決方法是recreate app,不過這也太麻煩了吧。不對!等等!我看到了什麼?recreate?re!?

······ ???!!!

天啦嚕,我怎麼忘記了重啟大法!!!

然後我滿懷期待地關掉了pycharm,重新打開了專案。

emmm,是在下輸了(哭)。

話說搜尋資料的時候,很不爽的事情是,大家總是說works fine,works fine。然而我一點都不fine。

相關推薦

django.db.utils.InternalError 1054 Unknown column 存在程式碼

解決方法請直接看結尾!!! 我本來是覺得這個問題這麼難解決,應該寫個blog一遍解決一邊記錄下各種嘗試過程,結果emmm。 我今天打算給一個點位(Point模型)新增照片(Photo模型,外來鍵Point模型)的時候,輸完p.photo_set.all()本來期待輸出&l

遷移檔案是報錯 django.db.utils.InternalError: (1054, "Unknown column 'name' in 'django_content_type'")

相信大家在做django遷移時有可能會遇到這樣的錯誤- django.db.utils.InternalError: (1054, “Unknown column ‘name’ in ‘django_content_type’”) 這個也是我遇到過得問題,

django 連線MYSQL時,資料遷移時報:django.db.utils.InternalError: (1366, "Incorrect string value: '\\xE9\\x97\\xAE\\xE9\\xA2\\x98' for column 'na

django 連線MYSQL時,資料遷移時報:django.db.utils.InternalError: (1366, "Incorrect string value: '\\xE9\\x97\\xAE\\xE9\\xA2\\x98' for column 'name' at row 5") 這個問題是由

django.db.utils.InternalError

ror erro name ... xe7 manage charset man 設置 django.db.utils.InternalError: (1366, "Incorrect string value: ‘\xE6\x96\x87\xE7\xAB\xA0

錯誤:django.db.utils.InternalError: (1050, "Table 'tb_books' already exists")

django中同步資料庫時出現錯誤(前面的忽略): 錯誤程式碼1050: pymysql.err.InternalError: (1050, "Table 'tb_books' already exists") 解決方法: python manage.py migrat

django.db.utils.InternalError: (1050, "Table 'tb_content' already exists")

在goods應用裡面寫了tb_content資料表的模型類(不該寫在這裡的),進行了資料遷移,還匯入了資料。 在contents應用裡也寫了tb_content資料表的模型類(應該寫在這裡的), 解決辦吧: 程式碼上,刪除goods裡面的。 python manage.py migrate c

解決“ raise errorclass, errorvalue django.db.utils.IntegrityError: (1048, "Column 'st_id' cannot be n”

一、問題描述 在建立超級使用者,新增完基本的資訊之後,就報錯顯示如下:  raise errorclass, errorvalue django.db.utils.IntegrityError: (1048, "Column 'st_id' cannot be null") -

資料遷移問題(django.db.utils.InternalError:(1050,"Table 'tb_content' already exists"))

django.db.utils.InternalError:(1050,“Table ‘tb_content’ already exists”)這個錯誤主要是重複匯入了已有的表格。 解決方法 先刪掉已生成的檔案如: 然後輸入: python manage.py makemigrat

資料庫與django makemigrations同步django.db.utils.OperationalError: (1060, "Duplicate column name 'azi1'")

產生背景:由於Models修改過於頻繁,而且多對多關係建了又重建,造成部分欄位在資料庫中已經存在,而django認為還沒有建立,繼續向資料庫建立這個欄位,導致錯誤,原因是資料庫不同步。 Microsoft Windows [版本 10.0.17134.345] (c) 2018 Microsof

django.db.utils.OperationalError: (1193, "Unknown system variable 'storage_engine'")

django連線資料庫時,配置 "OPTIONS":{"init_command":"SET storage_engine=INNODB;"} 1 如果mysql資料庫的版本是5.6,這句話會丟擲如下異常 django.db.utils.OperationalError: (119

解決:django.db.utils.OperationalError: unable to open database file

所在 git 目的 use 項目 文件 itl 報錯 log 這是一個從GitHub上下載的,一個網站項目的源碼。想要在自己的電腦上運行,期間過程相當曲折,不過至此終於是完成了。 1.安裝過程: python2->virtualenv->django1.9.8

django.db.utils.OperationalError: (1050, "Table '表名' already exists)解決方法

star 解決 數據庫表結構 opera -h django error ews copyto django.db.utils.OperationalError: (1050, "Table ‘表名‘ already exists)解決方法 找到解決方案,執行:

django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes');

ali iss xxxxx beat 字符串類型 參數設置 5.6 detail spa 在使用utf8mb4字符集的情況下,如果列存在索引,那麽varchar的最大長度是191 數據庫版本: 在使用utf8字符集的情況下,如果列存在索引,那麽varchar的最大長度是2

django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password:

Django錯誤又來了,資料庫的連線問題。。。。。。。。。出現django.db.utils.OperationalError: (1045, "Access denied for user ‘root‘@‘localhost‘ (using password: YES)")

SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'field list' -- IF查詢出錯

mysql IF() 查詢的時候出現這個錯誤 場景: user表 age欄位,查詢並輸出欄位 is_adult (0表示未成年,1表示已成年) 查詢語句如下: SELECT IF( age&g

解決“ django.db.utils.OperationalError: (1364, "Field 'birthday' doesn't have a default value"

一、問題描述 raise errorclass, errorvalue django.db.utils.OperationalError: (1364, "Field 'birthday' doesn't have a default value")   二、問題分析與解決

django.db.utils.OperationalError: 1050解決方案

摘要: 執行manage.py migrate解決報錯: django.db.utils.OperationalError: (1050, "Table '表名' already exists)解決方法 正在用django1.7初始化一個專案,資料庫表字段變更比較頻繁。

Linux - 運行 django 時 :django.db.utils.Notsupportederror: urls not supported

問題 png ots lin nds src pack utils python 運行 django 是異常:django.db.utils.Notsupportederror: urls not supported 原因:sqlite3版本3.7的問題 解決

django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes')

tree 大於 val pos 做的 let cat div ble 環境介紹 Django (2.1) Python 3.5.5 mysqlclient (1.4.2.post1) Mysql 5.6.28 RHEL 7.3 在migrate時候報錯

mysql命令 出現ERROR 1054 (42S22): Unknown column 'password' in 'field list'

list round services star 只需要 pass net code 報錯 1、安裝 brew install msyql 2、更新 brew upgrade mysql 3、啟動 To have launchd start mysql now and re