作者extron (extron)
看板Python
標題[問題] django 讀取現有資料庫
時間Tue Oct 20 14:44:50 2015
我在setting.py成功的將django連上我已經存在的MySql
在網路上看到的教學(包含官網的tutorial)
都先從create date -> save -> retrieve
但若我已經有現成的資料了 請問我怎麼透過django orm讀取資料庫?
假設我已經有一個table Fruit 並且含有很多水果的資料
於是我在 models.py 裡面
class Fruit(models.Model)
name = ...
color = ...
每個type都按照現有資料庫裏面Fruit的type去做宣告
也執行了
makemigrations 和
migrate
all_fruit = Fruit.objects.all()
print(all_fruit) 卻傳回 [] <-- 但是我資料庫裡明明有資料阿?
請問我該如何利用django orm 讀資料?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 172.89.32.145
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1445323492.A.3B4.html
→ drm343: 有沒有設定 db_table,django 的 model name 會加上 app 10/20 14:55
→ drm343: 名稱,可能他抓的跟你的 table 是不同的 10/20 14:56