[问题] 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