看板 Python 關於我們 聯絡資訊
小的前兩天才入門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 -------------------------------------------------------------------- #models.py class ContestEvent(models.Model): year = models.IntegerField(default=0) month = models.IntegerField(default=0) event_name = models.TextField(default="A") event_member = models.TextField(default="A") date_of_event = models.IntegerField(default=0) <=這欄位是被我誤填的 datetime為預設值的,現在修正為這樣 感謝各位指點迷津 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.251.1.226 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1443698178.A.752.html ※ 編輯: panasonic89 (60.251.1.226), 10/01/2015 19:17:34
ihcaoe: 試試1.先清掉資料庫 2.makemigrations 3.migrate 的結果 10/01 20:21
uranusjr: 如果可行的話資料庫整個砍掉重練最快 10/01 20:30
uranusjr: 否則需要把 migration 檔改回原本的樣子後 migrate 回上 10/01 20:31
uranusjr: 一個版本, 然後重新再做一次 10/01 20:31
drm343: 發完我的廢文才想到,你可能是在儲存 date_of_event 那邊 10/01 22:28
drm343: 直接寫了類似 int(datetime.datetime.now()) 這樣的程式碼 10/01 22:29
frank910138: 直接砍資料庫,重新建立table,比較快 10/02 00:15
panasonic89: 資料庫這邊我有砍掉那兩張表重蓋了 但是一樣 10/02 14:54
panasonic89: 我應該把全部的表都清空讓他重建嗎 10/02 14:54
ihcaoe: 樓上怎麼砍的? 10/02 21:14
frank910138: 要砍整個db 不只有表 10/03 13:04