Привет!
Добавляю поле date, но застревает когда делаю migrate и не добавляет в таблицу поле.
Ошибку выдает при migrate:
Когда перед migrate делаю makemigrations просит для существующих строк присвоить значения. Пробовал вводить и строку и число. Все равно ошибка.
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 160, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 97, in apply_migration
migration.apply(project_state, schema_editor)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 107, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 37, in database_forwards
field,
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/db/backends/schema.py", line 376, in add_field
definition, params = self.column_sql(model, field, include_default=True)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/db/backends/schema.py", line 121, in column_sql
default_value = self.effective_default(field)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/db/backends/schema.py", line 184, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 627, in get_db_prep_save
prepared=False)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1176, in get_db_prep_value
value = self.get_prep_value(value)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1171, in get_prep_value
return self.to_python(value)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1128, in to_python
parsed = parse_date(value)
File "/home/makarow/webapps/teleport/local/lib/python2.7/site-packages/django/utils/dateparse.py", line 37, in parse_date
match = date_re.match(value)
TypeError: expected string or buffer
Вот сама модель
class Item(models.Model):
name = models.CharField(max_length=250, verbose_name='Название фотографий', blank=True)
urlback = models.URLField(max_length=1000, verbose_name='Ссылка на контент')
user = models.ForeignKey(User)
url = models.URLField(max_length=1000, verbose_name='Ссылка')
public = models.IntegerField(verbose_name='Статус публикации', default=0)
date = models.DateTimeField(auto_now=False, auto_now_add=True)
def get_photos(self):
return Photo.objects.filter(item=self)
def get_photos_general(self):
return Photo.objects.filter(item=self, status=1)
def get_tags_with_url(self):
photos = Photo.objects.filter(item=self)
count_tags = 0
for photo in photos:
tags = Tag.objects.filter(photo=photo.id)
for tag in tags:
if 'http' in tag.url:
count_tags += 1
return count_tags
Где я спотыкнулся?
Спасибо