[問題] Django Migration設定出錯

作者: panasonic89 (panasonic)   2015-10-01 19:16:15
小的前兩天才入門Django
看著Django Girls的網站成功把example架了起來
最近參考
http://drumcoder.co.uk/blog/2010/jun/13/monthly-calendar-django/
這份範例想要把行事曆加入頁面中
但是在調整Models的時候似乎出現了問題
在 manage.py makemigrations的時候 似乎因為int 沒有initial value
所以他請我輸入
當時看他說明寫 datetime 也就照著打下去
結果在更新的時候會出現
int() argument must be a string or a number, not 'datetime.datetime'
於是上網查詢了一下
我修改了 0003 的migrate的資訊 把 datetime改為 default=0;
(也是唯一一個有看到datetime的migration file)
Server可以正常run 但執行首頁會出現一樣的問題
又google了一下把整個migration都清除
1. Erase every /migrations folder inside your apps
2. Go to the database and drop the **table name** table
(or delete its rows)
整個清除之後重新執行 python manage.py migrate
可以看到兩張table有重新產生 可是執行首頁依然出現
int() argument must be a string or a number, not 'datetime.datetime'
目前確定專案目錄下資料夾 migrations 已經不存在
想請問是不是還有哪些地方有所遺漏
以下附上部分錯誤訊息與 model程式碼
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.7.10
Exception Type: TypeError
Exception Value:
int() argument must be a string or a number, not 'datetime.datetime'
Exception Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/fields/__init__.py in get_prep_value, line 1601
Python Executable: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.10
Python Path:
['/Users/kumashi/Desktop/share/django/mysite',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
'/Library/Python/2.7/site-packages']
Server time: Thu, 1 Oct 2015 11:06:05 +0000
作者: ihcaoe (Ihc)   2015-10-01 20:21:00
試試1.先清掉資料庫 2.makemigrations 3.migrate 的結果
作者: uranusjr (←這人是超級笨蛋)   2015-10-01 20:30:00
如果可行的話資料庫整個砍掉重練最快否則需要把 migration 檔改回原本的樣子後 migrate 回上一個版本, 然後重新再做一次
作者: drm343 (一卡)   2015-10-01 22:28:00
發完我的廢文才想到,你可能是在儲存 date_of_event 那邊直接寫了類似 int(datetime.datetime.now()) 這樣的程式碼
作者: frank910138 (frank)   2015-10-02 00:15:00
直接砍資料庫,重新建立table,比較快
作者: panasonic89 (panasonic)   2015-10-02 14:54:00
資料庫這邊我有砍掉那兩張表重蓋了 但是一樣我應該把全部的表都清空讓他重建嗎
作者: ihcaoe (Ihc)   2015-10-02 21:14:00
樓上怎麼砍的?
作者: frank910138 (frank)   2015-10-03 13:04:00
要砍整個db 不只有表

Links booklink

Contact Us: admin [ a t ] ucptt.com