While running django when I use python manage.py migrate I am encountering the following error after running python manage.py makemigrations
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 234, in handle
fake_initial=fake_initial,
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/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 "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/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 "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/db/migrations/operations/fields.py", line 112, in database_forwards
field,
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 433, in add_field
definition, params = self.column_sql(model, field, include_default=True)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 161, in column_sql
default_value = self.effective_default(field)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/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 "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 789, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 1429, in get_db_prep_value
value = self.get_prep_value(value)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 1408, in get_prep_value
value = super().get_prep_value(value)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 1268, in get_prep_value
return self.to_python(value)
File "/Users/rasikraj/Desktop/eb-virt/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 1393, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
What could be the cause of this error and How can I ressolve this issue.
I'm using python 3.7 and Django 2.2
Based on the error, there is a DateTimeField [Django-doc] with as default='' [Django-doc]. But that is not a valid default: a DateTimeField should have store a datetime in the database (or None in case the field is NULL-able).
You thus should provide a valid default for that DateTimeField, for example:
from django.utils import timezone
class SomeModel(models.Model):
my_field = DateTimeField(default=timezone.now)
or you can omit the default value, and run makemigrations. In that case Django will ask if you want to provide a one-off default that will be applied to the records already in the database.
When you have changed the field you will need to remove the (invalid) migration file that was constructed where adding (or changing) that field took place, and make new migrations with manage.py makemigrations. After all, this validation does not occur when constructing the migration files, and now that you migrate it will indeed error. If you later change your model, the invalid migration fill is still not performed, hence it will raise the same error again.
Related
I've deployed my Django application to DigitalOcean server via nginx, gunicorn. Today I wanted to add the script models.DateTimeField(auto_now_add=True) for saving the date when message from user was sent, but during migration (after pulling the entire repository from github on ubuntu server) I'm getting following error. And I guess the problem is in migration files, but don't know how can I manipulate them on server and how to do it safely, without losing any data.
Error:
Applying pragmatechapp.0004_auto_20200328_1036...Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 234, in handle
fake_initial=fake_initial,
File "/home/kerimov/pragmatechproject/env/lib/python3.5/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 "/home/kerimov/pragmatechproject/env/lib/python3.5/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 "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/db/migrations/operations/fields.py", line 112, in database_forwards
field,
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 433, in add_field
definition, params = self.column_sql(model, field, include_default=True)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 161, in column_sql
default_value = self.effective_default(field)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/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 "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 793, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1435, in get_db_prep_value
value = self.get_prep_value(value)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1414, in get_prep_value
value = super().get_prep_value(value)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1274, in get_prep_value
return self.to_python(value)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1375, in to_python
parsed = parse_datetime(value)
File "/home/kerimov/pragmatechproject/env/lib/python3.5/site-packages/django/utils/dateparse.py", line 106, in parse_datetime
match = datetime_re.match(value)
TypeError: expected string or bytes-like object
Note: I should solve this problem very quickly, please, everyone, who knows the answer, help me. I'm really depressed and stressed.
As a solution I've used deleting the migrations one by one with a command find . -path "*/migrations/{my_migration_names}.py" -not -name "__init__.py" -delete. To get name of all of my migration files you should run python3 manage.py showmigrations command.
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.
I added the following code in models.py :
class Conference(models.Model):
conf_name = models.CharField(max_length=250)
location = models.CharField(max_length=500)
note = models.TextField(max_length=500)
note2 = models.TextField(max_length=500)
date_from = models.DateField()
date_to = models.DateField()
time_from = models.TimeField(default='HH:MM:ss')
time_to = models.TimeField(default='HH:MM:ss')
After that I ran migration commands and I got the following traceback :
WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'appadmin'
HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode
?: (urls.W005) URL namespace 'dev_app' isn't unique. You may not be able to reverse all URLs in this namespace
Operations to perform:
Apply all migrations: admin, auth, contenttypes, dev_app, sessions
Running migrations:
Applying dev_app.0016_auto_20180112_0630...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/usr/lib/python2.7/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 "/usr/lib/python2.7/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 "/usr/lib/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/lib/python2.7/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/usr/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 86, in database_forwards
field,
File "/usr/lib/python2.7/site-packages/django/db/backends/mysql/schema.py", line 48, in add_field
super(DatabaseSchemaEditor, self).add_field(model, field)
File "/usr/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 414, in add_field
definition, params = self.column_sql(model, field, include_default=True)
File "/usr/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 154, in column_sql
default_value = self.effective_default(field)
File "/usr/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 228, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "/usr/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 766, in get_db_prep_save
prepared=False)
File "/usr/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 2277, in get_db_prep_value
value = self.get_prep_value(value)
File "/usr/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 2272, in get_prep_value
return self.to_python(value)
File "/usr/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 2259, in to_python
params={'value': value},
django.core.exceptions.ValidationError: [u"'null' value has an invalid format. It must be in HH:MM[:ss[.uuuuuu]] format."]
Even after I reverted the code in models.py, the traceback has persisted.
I need help understanding the traceback.
The code was working properly before the changes in models were applied. The models migrated properly.
I also flushed the database and tried to migrate again, it gave the same result.
Your time_from and time_to default is wrong. You should provide a default value not a format. If your model is new remove the migration file (I think dev_app.0016_auto_20180112_0630) change default values and run manage.py makemigrations again.
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
I created a new model names Join with three fields, email, timestamp and updated timestamp. But, the databse sync started giving me error to add default values to create table. I added some random values and now it has started giving me totally random errors beyond my understanding. Please help here.
Here's my model:
class Join(models.Model):
email = models.EmailField(default="default#default.com")
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False, default = "")
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
def __unicode__(self):
return self.email
And here's the error:
(learn_django) C:\Users\ajhavery\Desktop\learn_django\source>python manage.py ma
kemigrations
Migrations for 'joins':
0004_auto_20150320_2358.py:
- Alter field timestamp on join
- Alter field updated on join
(learn_django) C:\Users\ajhavery\Desktop\learn_django\source>python manage.py mi
grate
Operations to perform:
Apply all migrations: admin, contenttypes, joins, auth, sessions
Running migrations:
Applying joins.0002_auto_20150320_2346...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\core\man
agement\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\core\man
agement\__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\core\man
agement\base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\core\man
agement\base.py", line 338, in execute
output = self.handle(*args, **options)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\core\man
agement\commands\migrate.py", line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\migra
tions\executor.py", line 68, in migrate
self.apply_migration(migration, fake=fake)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\migra
tions\executor.py", line 102, in apply_migration
migration.apply(project_state, schema_editor)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\migra
tions\migration.py", line 108, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, ne
w_state)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\migra
tions\operations\fields.py", line 37, in database_forwards
field,
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\backe
nds\sqlite3\schema.py", line 179, in add_field
self._remake_table(model, create_fields=[field])
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\backe
nds\sqlite3\schema.py", line 75, in _remake_table
self.effective_default(field)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\backe
nds\schema.py", line 188, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\model
s\fields\__init__.py", line 627, in get_db_prep_save
prepared=False)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\model
s\fields\__init__.py", line 1290, in get_db_prep_value
value = self.get_prep_value(value)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\model
s\fields\__init__.py", line 1269, in get_prep_value
value = super(DateTimeField, self).get_prep_value(value)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\model
s\fields\__init__.py", line 1171, in get_prep_value
return self.to_python(value)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\model
s\fields\__init__.py", line 1252, in to_python
params={'value': value},
django.core.exceptions.ValidationError: [u"'00:00:00' value has an invalid forma
t. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
Any help please.
When Django asks "add default values to create table", you need to create values that resonate with the TYPE of that particular column.
Your error is apparent here:
django.core.exceptions.ValidationError: [u"'00:00:00' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
The "random" values you entered must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format.
Remove the DateTimeFields from the model, remigrate, and start over. This time, when you're asked to put in default values, put it a random 'datetime' (i.e. 2006-10-25 14:30:59).
Source: https://docs.djangoproject.com/en/1.7/ref/forms/fields/#datetimefield
Best,
aj