[問題] django orm 讀取現有資料庫

作者: extron (extron)   2015-10-20 14:44:50
我在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) 卻傳回 [] <
作者: drm343 (一卡)   2015-10-20 14:55:00
有沒有設定 db_table,django 的 model name 會加上 app名稱,可能他抓的跟你的 table 是不同的

Links booklink

Contact Us: admin [ a t ] ucptt.com