django datetime declaration error - python

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.

Related

Django manage.py migrate ValidationError

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.

Django- Change Username field to BigAutoField?

I'm designing an Application where username will be an AutoIntegerField and unique.
Here's my model.
class ModelA(models.Model):
username = models.BigAutoField(primary_key=True, db_index=False)
user_id = models.UUIDField(default=uuid.uuid4, unique=True,
editable=False)
Initially, I wanted user_id to be a primary_key, but I can't create an AutoField which is not primary_key. As a result, I'd to let go off user_id as primary_key and assigned username as the primary key.
Now, when I run the migrations, it throws an error saying,
django.db.utils.ProgrammingError: operator class "varchar_pattern_ops" does not accept data type bigint
Complete StackTrace:-
Applying users.0005_auto_20180626_0914...Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: operator class "varchar_pattern_ops" does not accept data type bigint
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/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 "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/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 "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/migrations/operations/fields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 515, in alter_field
old_db_params, new_db_params, strict)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/backends/postgresql/schema.py", line 112, in _alter_field
new_db_params, strict,
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 684, in _alter_field
params,
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 120, in execute
cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/backends/utils.py", line 80, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: operator class "varchar_pattern_ops" does not accept data type bigint
I think the issue is that you still have an old index on your username field that clashes with the new type. The db_index=False argument has no effect because primary_key=True always generates an index.
You might be able to solve this by removing primary_key=True, creating a migration, and then re-adding it and creating another migration. Alternatively, you can do it by hand by dropping and re-creating the index. If you want to go down that path, consult this answer.
If your project is still in an early stage and you don't have any valuable data, you can take the easy way out and drop any tables related to your users app or even the complete database, delete all migrations in the users app and create them from scratch.
in my case I was connecting django to postgres at localhost pgadmin
first deleted all the migrations except default one and also in the pycache
then just run python manage.py makemigrations and python manage.py migrate in your terminal

Getting Migrate Error on Model Field that doesn't exist

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.

Issues Deploying Django Application to AWS because of Date model

I am trying to do a simple sign in application using Django and host it on AWS using Amazon Linux
My model is
class Work(models.Model):
user = models.CharField(_("User"), max_length = 50, default = None)
intern = models.ForeignKey("Intern", default = 1)
date = models.DateField(_("Date"), default= timezone.now().today(), blank=True)
time_in = models.TimeField(_("Time In"),default= timezone.now().time(), blank=True)
time_out = models.TimeField(_("Time Out"),default= timezone.now().time(), blank=True)
I have tried timezone.now().time and datetime.datetime.now().time() and none of these work
When I try to run migrate on the server I get this error log
Apply all migrations: admin, auth, clockin, contenttypes, database, sessions, watson
Running migrations:
Applying clockin.0006_auto_20170523_1101...System check identified some issues:
WARNINGS:
clockin.Work.date: (fields.W161) Fixed default value provided.
HINT: It seems you set a fixed date / time / datetime value as default for this field. This may not be what you want. If you want to have the current date as default, use `django.utils.timezone.now`
Traceback (most recent call last):
File "pmi_alpha/manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/opt/python/run/venv/local/lib/python3.4/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 "/opt/python/run/venv/local/lib/python3.4/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 "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 204, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 495, in alter_field
old_db_params, new_db_params, strict)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 578, in _alter_field
new_default = self.effective_default(new_field)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 199, in effective_default
default = field.get_default()
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 769, in get_default
return self.default()
TypeError: localtime() missing 1 required positional argument: 'value'
(ElasticBeanstalk::ExternalInvocationError)
For me this seemed to be an issue with mySQL that I was using as my database. I solved this by moving to the default sqlLite file.

Changed Django model attribute and now getting error for it

I had a model with a DateField that worked just fine. I wanted to change it from a DateField to a CharField.
Before:
class NWEAScore(models.Model):
test_date = models.DateField(default=date.today, verbose_name='Test Date')
After:
class NWEAScore(models.Model):
year = models.CharField(max_length=50, choices=YEAR_CHOICES, default=SIXTEEN)
season = models.CharField(max_length=50, choices=SESSION_CHOICES, default=FALL)
Not sure what went wrong but now I'm getting an error.
Making migrations is no problem. I make them and then upload them to my server, then when I migrate, I get an error.
The Error I get when I try to apply my migrations:
(venv) alex#newton:~/newton$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, amc, auth, brain, contenttypes, ixl, nwea, sessions
Running migrations:
Rendering model states... DONE
Applying brain.0021_auto_20160927_0038... OK
Applying nwea.0011_auto_20160927_0038...Traceback (most recent call last):
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/models/options.py", line 612, in get_field
return self.fields_map[field_name]
KeyError: 'test_date'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 202, in handle
targets, plan, fake=fake, fake_initial=fake_initial
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 97, in migrate
state = self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 132, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 237, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/migrations/operations/models.py", line 525, in database_forwards
getattr(new_model._meta, self.option_name, set()),
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 329, in alter_unique_together
self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 352, in _delete_composed_index
columns = [model._meta.get_field(field).column for field in fields]
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 352, in <listcomp>
columns = [model._meta.get_field(field).column for field in fields]
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/models/options.py", line 614, in get_field
raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: NWEAScore has no field named 'test_date'
I went through and deleted all my instances from all my models, just incase a remaining "NWEAScore" Instance with a test_date was throwing the error.
I searched through my entire project for the term "test_date", trying to delete every instance, and the only remaining instances are in old migrations. Should I go back and delete those? Could that be throwing that off? I'm not too clear on how to wipe migrations and make new ones if that's it.
I gave it a shot for a few days, if anyone has suggestions thanks in advance!
Go to the migrations folder of your app and delete all files, except __init__.py. Then run the command:
python manage.py makemigrations
to make new migrations with the updated fields

Categories