[問題] django orm 讀取現有資料庫
我在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
→
10/20 14:55, , 1F
10/20 14:55, 1F
→
10/20 14:56, , 2F
10/20 14:56, 2F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章