日期时间字段不迁移 django
datetime field not migrating django
当我更改模型并添加 datefield
时,迁移不起作用。以下是我添加的内容:
Birth=models.DateField(editable=False,blank=True)
我得到的错误是:
match= date_re.match TypeError: expected string or buffer
根据 Django 文档,第一步是更改模型,然后 运行 进行迁移。
例如
$ python manage.py makemigrations
你运行这个代码后,它将显示为
Migrations for 'books': 0003_auto.py:
- Alter field author on book
然后:
一旦您有了新的迁移文件,您应该将它们应用到您的数据库以确保它们按预期工作:
为此,您需要 运行
$ python manage.py migrate
会显示
Operations to perform: Synchronize unmigrated apps: sessions, admin,
messages, auth, staticfiles, contenttypes Apply all migrations:
books Synchronizing apps without migrations: Creating tables...
Installing custom SQL... Installing indexes... Installed 0 object(s)
from 0 fixture(s) Running migrations: Applying books.0003_auto... OK
就是这样。
供参考:
https://docs.djangoproject.com/en/1.8/topics/migrations/
当我更改模型并添加 datefield
时,迁移不起作用。以下是我添加的内容:
Birth=models.DateField(editable=False,blank=True)
我得到的错误是:
match= date_re.match TypeError: expected string or buffer
根据 Django 文档,第一步是更改模型,然后 运行 进行迁移。
例如
$ python manage.py makemigrations
你运行这个代码后,它将显示为
Migrations for 'books': 0003_auto.py: - Alter field author on book
然后: 一旦您有了新的迁移文件,您应该将它们应用到您的数据库以确保它们按预期工作:
为此,您需要 运行
$ python manage.py migrate
会显示
Operations to perform: Synchronize unmigrated apps: sessions, admin, messages, auth, staticfiles, contenttypes Apply all migrations: books Synchronizing apps without migrations: Creating tables...
Installing custom SQL... Installing indexes... Installed 0 object(s) from 0 fixture(s) Running migrations: Applying books.0003_auto... OK
就是这样。
供参考: https://docs.djangoproject.com/en/1.8/topics/migrations/