作者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://webptt.com/cn.aspx?n=bbs/Python/M.1445323492.A.3B4.html
1F:→ drm343: 有没有设定 db_table,django 的 model name 会加上 app 10/20 14:55
2F:→ drm343: 名称,可能他抓的跟你的 table 是不同的 10/20 14:56