为什么我用这个Django迁移得到一个TypeError?

时间:2015-08-10 05:17:11

标签: python django migration

from django.db import models
from user.models import CustomeUser

# Create your models here.


class FoodGroup(models.Model):
    name = models.CharField(max_length=127)
    photo = models.FileField(upload_to="photos/", null=True, blank=True)
    presenter_photo = models.FileField(upload_to="photos/", null=True, blank=True)
    explain = models.TextField()

    def __str__(self):
        return self.name

class Food(models.Model):
    name = models.CharField(max_length=127)
    photo = models.FileField(upload_to="photos/",null=True, blank=True, default ="photos/backgrounddefault.jpg")
    summary = models.TextField()
    foodGroup = models.ForeignKey(FoodGroup , related_name = 'food_for_foodGroupg')

    def __str__(self):
        return self.name

class Benefit(models.Model):
    text = models.TextField()
    food = models.ForeignKey(Food)

    def __str__(self):
        return self.text

class Disadvantage(models.Model):
    text = models.TextField()
    food = models.ForeignKey(Food)

    def __str__(self):
        return self.text

class RowTable(models.Model):
    name = models.CharField(max_length=127)
    total = models.FloatField()
    food = models.ForeignKey(Food , related_name = 'table')

    def __str__(self):
        return self.food.name + " : " + self.name;

class Illness(models.Model):
    name = models.CharField(max_length = 127)
    food = models.ManyToManyField(Food, related_name = 'illnesses')

    def __str__(self):
        return self.name;

class Source(models.Model):
    link = models.CharField(max_length = 127)
    name = models.CharField(max_length = 127)
    food = models.ForeignKey(Food , related_name = 'Sources')

    def __str__(self):
        return self.name;

class SiteInfo(models.Model):
    date = models.CharField(max_length = 127)
    main_photo = models.FileField(upload_to="photos/", null=True, blank=True)
    logo = models.FileField(upload_to="photos/", null=True, blank=True)

 def __str__(self):
     return self.date


class Post(models.Model):
    user = models.ForeignKey(CustomeUser)
    text = models.TextField()
    like_count = models.IntegerField()

class Like(models.Model):
    user = models.ForeignKey(CustomeUser)
    Post = models.ForeignKey(Post)

当我迁移上面的代码时,我得到以下错误: 它以前工作过,但现在我不知道出了什么问题。

Applying mysite.0010_auto_20150810_0416...Traceback (most recent call last):
 File "manage.py", line 10, in <module>
 execute_from_command_line(sys.argv)
 File "/Users/kamran/django-trunk/django/core/management/__init__.py", line 330, in execute_from_command_line
 utility.execute()
 File "/Users/kamran/django-trunk/django/core/management/__init__.py", line 322, in execute
 self.fetch_command(subcommand).run_from_argv(self.argv)
 File "/Users/kamran/django-trunk/django/core/management/base.py", line 347, in run_from_argv
 self.execute(*args, **cmd_options)
 File "/Users/kamran/django-trunk/django/core/management/base.py", line 398, in execute
 output = self.handle(*args, **options)
 File "/Users/kamran/django-trunk/django/core/management/commands/migrate.py", line 195, in handle
 executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
 File "/Users/kamran/django-trunk/django/db/migrations/executor.py", line 110, in migrate
 self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
 File "/Users/kamran/django-trunk/django/db/migrations/executor.py", line 147, in apply_migration
 state = migration.apply(state, schema_editor)
 File "/Users/kamran/django-trunk/django/db/migrations/migration.py", line 116, in apply
 operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
 File "/Users/kamran/django-trunk/django/db/migrations/operations/fields.py", line 62, in database_forwards
 field,
 File "/Users/kamran/django-trunk/django/db/backends/sqlite3/schema.py", line 218, in add_field
 self._remake_table(model, create_fields=[field])
 File "/Users/kamran/django-trunk/django/db/backends/sqlite3/schema.py", line 100, in _remake_table
 self.effective_default(field)
 File "/Users/kamran/django-trunk/django/db/backends/base/schema.py", line 210, in effective_default
 default = field.get_db_prep_save(default, self.connection)
 File "/Users/kamran/django-trunk/django/db/models/fields/__init__.py", line 715, in get_db_prep_save prepared=False)
 File "/Users/kamran/django-trunk/django/db/models/fields/__init__.py", line 1297, in get_db_prep_value
 value = self.get_prep_value(value)
 File "/Users/kamran/django-trunk/django/db/models/fields/__init__.py", line 1292, in get_prep_value
 return self.to_python(value)
 File "/Users/kamran/django-trunk/django/db/models/fields/__init__.py", line 1256, in to_python
 parsed = parse_date(value)
 File "/Users/kamran/django-trunk/django/utils/dateparse.py", line 60, in parse_date
 match = date_re.match(value)
 TypeError: expected string or buffer

我没有使用任何dateField,但是当我想要迁移程序时,我仍然收到此错误。

0 个答案:

没有答案