[問題] 請問Django如何新增column
我是用sqlite3資料庫,python2.7
跟著Django官方網站教學在做
要加入一個column:
num_pages = models.IntegerField(blank=True, null=True)
書上說要做幾個動作
1. Add the field to your model.
2. Run manage.py sqlall [yourapp] to see the new CREATE TABLE statement for
the model. Note the column definition for the new field.
3. Start your database’s interactive shell (e.g., psql or mysql, or you can
use manage.py dbshell). Execute an ALTER TABLE statement that adds your
new column.
我前兩個完成了,第三個說Start your database’s interactive shell
sqlite3本身就跟python2.7在一起,我是直接將ALTER TABLE打在python shell裡
ALTER TABLE books_book ADD COLUMN num_pages integer
顯示SyntaxError
想說在cmd中執行manage.py dbshell看看,也顯示sqlite3錯誤訊息
不知該怎麼增加新的欄位了
還請幫忙解決,謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.32.115.169
→
09/07 15:23, , 1F
09/07 15:23, 1F
推
09/07 16:23, , 2F
09/07 16:23, 2F
→
09/07 16:36, , 3F
09/07 16:36, 3F
→
09/07 17:02, , 4F
09/07 17:02, 4F
→
09/07 17:02, , 5F
09/07 17:02, 5F
→
09/07 17:03, , 6F
09/07 17:03, 6F
我本來是只打sqlite3而已,剛剛改成django.db.backends.sq,輸入manage.py dbshell
後還是不行...,同樣的錯誤訊息,(sqlite3,不是內部或外部命令,可執行的程式或
批次檔。)
db我是像下面這樣設定
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'C:/Python27/Lib/site-packages/django/bin/mysite/db/test.db',
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost.
Not used with sqlite3.
'PORT': '', # Set to empty string for default.
Not used with sqlite3.
}
}
※ 編輯: Jason1122 來自: 114.32.115.169 (09/07 19:11)
推
09/07 19:42, , 7F
09/07 19:42, 7F
→
09/07 19:43, , 8F
09/07 19:43, 8F
→
09/07 19:43, , 9F
09/07 19:43, 9F
剛剛找到類似的問題,http://www.zeuux.org/group/django/bbs/content/6442/
照著做解決了,要再去下載db shell,設定好目錄位置之後再執行python manage.py
就可以進入了
※ 編輯: Jason1122 來自: 114.32.115.169 (09/07 20:06)
推
09/07 20:26, , 10F
09/07 20:26, 10F
推
09/08 00:55, , 11F
09/08 00:55, 11F