I am stuck with migrations in django. I have two really basic models that will not migrate:
from django.db import models
# Create your models here.
class Instanz(models.Model):
type = models.CharField(max_length=30)
angelegt_am = models.DateField(auto_now_add=True)
class Person(models.Model):
instanz_fk = models.ForeignKey('Instanz', on_delete=models.CASCADE)
last_name = models.CharField(max_length=30)
first_name = models.CharField(max_length=30)
geburtsdatum = models.DateField()
It will raise the following exception. I dont get why it will search for a field named PROTECT. I used models.PROTECT in earlier migrations, before switching to CASCADE, but not any longer...
Operations to perform:
Apply all migrations: admin, auth, contenttypes, kundencenter, sessions
Running migrations:
Applying kundencenter.0001_initial...Traceback (most recent call last):
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\models\options.py", line 617, in get_field
return self.fields_map[field_name]
KeyError: 'PROTECT'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool\manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\core\management\base.py", line 345, in execute
output = self.handle(*args, **options)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
fake_initial=fake_initial,
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\migrations\executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\migrations\executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\migrations\migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\migrations\operations\models.py", line 96, in database_forwards
schema_editor.create_model(model)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\backends\base\schema.py", line 246, in create_model
definition, extra_params = self.column_sql(model, field)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\backends\base\schema.py", line 136, in column_sql
db_params = field.db_parameters(connection=self.connection)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\models\fields\related.py", line 940, in db_parameters
return {"type": self.db_type(connection), "check": self.db_check(connection)}
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\models\fields\related.py", line 937, in db_type
return self.target_field.rel_db_type(connection=connection)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\models\fields\related.py", line 855, in target_field
return self.foreign_related_fields[0]
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\models\fields\related.py", line 595, in foreign_related_fields
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\models\fields\related.py", line 582, in related_fields
self._related_fields = self.resolve_related_fields()
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\models\fields\related.py", line 575, in resolve_related_fields
else self.remote_field.model._meta.get_field(to_field_name))
File "C:\Users\Micha\Dropbox\PycharmProjects\vertriebstool_virtualenv\lib\site-packages\django\db\models\options.py", line 619, in get_field
raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: Instanz has no field named 'PROTECT'
Here's the deal: I messed up some earlier migrations that were blocking the process, because Djangos migrate uses all unaplied migrations.
I had to go to the folder \\migrations and delete all files (except init.py of course).
Everything works like a charm now.
If this happens in production, you would probably delete only the migrations to the point of the last working migration...
Related
Every time I run python3 manage.py migrate I get the same error about one of the fields in the model class. Even after deleting the field, the same error occurs.
This is what the model class looks like:
class Events(models.Model):
name = models.CharField(max_length=200, null=True)
date = models.DateTimeField(editable=True, null=True)
sport = models.CharField(max_length=200, null=True)
location = models.CharField(max_length=200, null=True)
description = models.CharField(max_length=200, null=True, blank=True)
date_created = models.DateTimeField(auto_now_add=True)
tags = models.ManyToManyField(Tag)
num_seats = models.IntegerField(null=True, blank=True)
creator = models.CharField(max_length=200, null=False)
And this is what the error looks like:
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'IntegerField'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/laithtahboub/Desktop/Programming/Django/events_project/manage.py", line 22, in <module>
main()
File "/Users/laithtahboub/Desktop/Programming/Django/events_project/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/__init__.py", line 419, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/base.py", line 373, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/base.py", line 417, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/base.py", line 90, in wrapped
res = handle_func(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 253, in handle
post_migrate_state = executor.migrate(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/migrations/executor.py", line 126, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/migrations/executor.py", line 156, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/migrations/executor.py", line 236, in apply_migration
state = migration.apply(state, schema_editor)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/migrations/migration.py", line 125, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/migrations/operations/fields.py", line 225, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/backends/sqlite3/schema.py", line 140, in alter_field
super().alter_field(model, old_field, new_field, strict=strict)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 618, in alter_field
self._alter_field(model, old_field, new_field, old_type, new_type,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/backends/sqlite3/schema.py", line 362, in _alter_field
self._remake_table(model, alter_field=(old_field, new_field))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/backends/sqlite3/schema.py", line 202, in _remake_table
'default': self.quote_value(self.effective_default(new_field))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 334, in effective_default
return field.get_db_prep_save(self._effective_default(field), self.connection)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 839, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 834, in get_db_prep_value
value = self.get_prep_value(value)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 1824, in get_prep_value
raise e.__class__(
TypeError: Field 'num_seats' expected a number but got <django.db.models.fields.IntegerField>.
Let me know if you need to see another file to determine the problem. I'm aware that there are many similar questions to this one on Stack Overflow, but please keep in mind that I have tried almost everything I can based on the answers of these questions, and nothing has worked yet.
After deleting the field from the model class, you need to run python manage.py makemigrations before running python manage.py migrate
So the issue was fixed by deleting all the files inside the migrations folder except the __init__.py file.
And removing all the rows from django_migrations table
And re-applying fake migrations by python manage.py migrate --fake
This fixed the issue. (OP and me had a call to get the issue fixed)
I created an app two days ago, added some models, and migrated successfully. And since, I haven't added or changed anything but I added something today and tried to migrate, after making migrations and tried to migrate, I got this error:
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, students, user_upload
Running migrations:
Applying user_upload.0002_users_upload_phone_number...Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\base.py", line 371, in execute
output = self.handle(*args, **options)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\core\management\commands\migrate.py", line 243, in handle
post_migrate_state = executor.migrate(
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\migrations\operations\fields.py", line 104, in database_forwards
schema_editor.add_field(
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\backends\sqlite3\schema.py", line 328, in add_field
self._remake_table(model, create_field=field)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\backends\sqlite3\schema.py", line 189, in _remake_table
self.effective_default(create_field)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\backends\base\schema.py", line 303, in effective_default
return field.get_db_prep_save(self._effective_default(field), self.connection)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\models\fields\__init__.py", line 1512, in get_db_prep_save
return connection.ops.adapt_decimalfield_value(self.to_python(value), self.max_digits, self.decimal_places)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\backends\base\operations.py", line 523, in adapt_decimalfield_value
return utils.format_number(value, max_digits, decimal_places)
File "C:\Users\aser\AppData\Roaming\Python\Python38\site-packages\django\db\backends\utils.py", line 235, in format_number
value = value.quantize(decimal.Decimal(1).scaleb(-decimal_places), context=context)
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
I've been looking but can't really find what's wrong
This is my model
from django.db import models
from django.forms import ModelForm
class Users_Upload(models.Model):
first_name = models.CharField(max_length=120)
last_name = models.CharField(max_length=120)
email = models.CharField(max_length=120)
phone_number = models.DecimalField(max_digits=14, decimal_places=4)
address = models.CharField(max_length=120, default="Bay Area, San Francisco, California, USA")
and my admin
from django.contrib import admin
from .models import Users_Upload
admin.site.register(Users_Upload)
I've already solved it. I had to clear out all my migrations and re-migrate again.
I'm trying to override the save method and I think I write exactly what the document said, but get the error
from django.db import models
class Post(models.Model):
name = models.CharField(max_length = 20)
lower_name = models.CharField(max_length = 20)
def save(self, *args, **kwargs):
if not self.lower_name:
self.lower_name = self.name.lower()
super().save(*args, **kwargs)
here is the traceback when I call python manage.py migrate
(project_site) λ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, works
Running migrations:
Applying works.0018_post_url_name...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\core\management\commands\migrate.py", line 234, in handle
fake_initial=fake_initial,
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\migrations\executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\migrations\operations\fields.py", line 112, in database_forwards
field,
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\backends\sqlite3\schema.py", line 327, in add_field
self._remake_table(model, create_field=field)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\backends\sqlite3\schema.py", line 188, in _remake_table
self.effective_default(create_field)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\backends\base\schema.py", line 233, in effective_default
return field.get_db_prep_save(self._effective_default(field), self.connection)
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\backends\base\schema.py", line 212, in _effective_default
default = field.get_default()
File "D:\Code\Python\project_site\.venv\lib\site-packages\django\db\models\fields\__init__.py", line 797, in get_default
return self._get_default()
TypeError: save() missing 1 required positional argument: 'self'
python version: 3.6.8 django version: 2.2.4
Ran my server today and realized I had 'two unapplied migrations'. I ran the command makemigrations and it detected no change, so naturally I then ran migrate.
I get this error code on my terminal:
Applying Campaigns.0016_campaignrecruit_date...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", l
ine 371, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", l
ine 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line
288, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line
335, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/migrat
e.py", line 200, in handle
fake_initial=fake_initial,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/executor.py", lin
e 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/executor.py", lin
e 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/executor.py", lin
e 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/migration.py", li
ne 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/operations/fields
.py", line 84, in database_forwards
field,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py",
line 306, in add_field
self._remake_table(model, create_field=field)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py",
line 178, in _remake_table
self.effective_default(create_field)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/base/schema.py", li
ne 240, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 767, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 1276, in get_db_prep_value
value = self.get_prep_value(value)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 1271, in get_prep_value
return self.to_python(value)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 1233, in to_python
parsed = parse_date(value)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/dateparse.py", line 74, i
n parse_date
match = date_re.match(value)
TypeError: expected string or bytes-like object
So to me, it looks like a date field in my model campaignrecruit is getting an input that it doesn't know how to handle. Which I would understand. But the thing is I don't have a datefield in my campaignrecruit model. The Time field is intentionally commented out right now.
Here's my models.py:
class campaignrecruit(models.Model):
campaign = models.ForeignKey(startcampaign, on_delete=models.CASCADE)
volunteer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
join = models.BooleanField()
#Time = models.IntegerField()
def __str__(self):
return str(self.volunteer)
What else would throw this error? Any and all help is appreciated.
Since no one else answered, I will. As Aritra stated, I totally forgot about the migration files that are created whenever you run the migrate command. I had removed these model fields from my models and whenever I migrated again there was an error removing the files in my migrations file. After manually going in and removing the files, my error was fixed.
The database was just out of sync with what django had in its files.
Models.py
class user_Roles(models.Model):
code = models.CharField(max_length=20)
description = models.CharField(max_length=30)
permitted_menus = models.CharField(max_length=200)
created = models.DateTimeField(auto_now_add=True,blank=True,null=True)
I cannot add a datetime, date or time fields in models. It shows that "[u"'' value has an invalid format. It must be in HH:MM[:ss[.uuuuuu]] format."]" while migrating the database. How to fix it??
Error
Running migrations:
Rendering model states... DONE
Applying myapp.0025_auto_20160321_0913...Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 222, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 110, in migrate
self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 148, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 115, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/usr/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 201, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 484, in alter_field
old_db_params, new_db_params, strict)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 567, in _alter_field
new_default = self.effective_default(new_field)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 211, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 710, in get_db_prep_save
prepared=False)
File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 2293, in get_db_prep_value
value = self.get_prep_value(value)
File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 2288, in get_prep_value
return self.to_python(value)
File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 2275, in to_python
params={'value': value},
django.core.exceptions.ValidationError: [u"'' value has an invalid format. It must be in HH:MM[:ss[.uuuuuu]] format."]
After removing the created field also, it shows the same error..
Delete the migration folder. And then execute
python manage.py makemigrations
python manage.py migrate
You can modify the created field like this
created = models.DateTimeField(default=date.today, blank=True,null=True)
Check the documentation for auto_now_add