I have a Django project which has been developed with Python2.7, it is currently using Django version 1.10. I am now in the process of upgrading - first to Python3, and then afterwards I will do the Django upgrade.
When I make Python3 virtual environment and run the tests:
venv bash% ./manage.py tests
I get a massive traceback:
Traceback (most recent call last):
File "./manage.py", line 9, in <module>
execute_from_command_line( sys.argv )
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/commands/test.py", line 29, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/commands/test.py", line 72, in handle
failures = test_runner.run_tests(test_labels)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/test/runner.py", line 549, in run_tests
old_config = self.setup_databases()
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/test/runner.py", line 499, in setup_databases
self.parallel, **kwargs
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/test/runner.py", line 743, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db
run_syncdb=True,
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 130, in call_command
return command.execute(*args, **defaults)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 202, in handle
targets, plan, fake=fake, fake_initial=fake_initial
File "/home/hove/sleipner/venv/lib/python3.5/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/hove/sleipner/venv/lib/python3.5/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/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 237, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/hove/sleipner/venv/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 "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/operations/models.py", line 96, in database_forwards
schema_editor.create_model(model)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 271, in create_model
self.quote_name(field.column),
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 115, in quote_name
return self.connection.ops.quote_name(name)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/sqlite3/operations.py", line 153, in quote_name
if name.startswith('"') and name.endswith('"'):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
As I understand it the problem is unicode/string issues in the migrations? I have tried to follow the advice: "Add from __future__ import unicode_literals at the top every module". The resulting code still works nicely in Python2.7, but manage.py test fails in the same way for Python3.
For all it is worth the project seems to "basically" work in Python3 when I do:
bash% manage.py runserver
Update:
These are my database settings - might very well be something wrong with this, but observe that it has worked in Python2.7 for many years - and still does:
if "test" in sys.argv:
DATABASES = { 'default' : {
"ENGINE" : "django.db.backends.sqlite3",
"NAME" : "friskby.sqlite",
"TEST" : {
"NAME" : "friskby-test.sqlite"}}}
else:
DATABASE_URL = os.environ.get("DATABASE_URL")
if DATABASE_URL:
config = dj_database_url.config(default = DATABASE_URL)
DATABASES = { 'default': config }
else:
raise Exception("The DATABASE_URL environment variable has not bee set")
The comment from #Will Keeling set me on the right track. My migrations (originally created with Python2.7) had many:
... db_column = b"NAME_OF_COLUMN", ...
statements. I just removed all the leading b - and lo and behold all tests pass in both Python2.7 and Python3.
Related
I've recently upgraded form sqlite to postgresql for my django project.
In the past, whenever I've made a change to a model, I simply ran makemigrations and then the migrate command. No issues.
Now, with posgresql, when I make the INITIAL makemigrations/migrate, it works fine as per usual, but if I make a change to a model and then run makemigrations and then migrate, on the 'migrate' command, the system tries to apply the initial migration again and returns an error saying the table already exist (which it does).
How can I run migrate without the system trying to remigrate migrations that have already been migrated?
Thanks!
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/jimmy/lib/python3.6/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/jimmy/lib/python3.6/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/jimmy/lib/python3.6/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/jimmy/lib/python3.6/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/home/jimmy/lib/python3.6/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/jimmy/lib/python3.6/django/core/management/commands/migrate.py", line 233, in handle
fake_initial=fake_initial,
File "/home/jimmy/lib/python3.6/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/jimmy/lib/python3.6/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/jimmy/lib/python3.6/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/jimmy/lib/python3.6/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/jimmy/lib/python3.6/django/db/migrations/operations/models.py", line 92, in database_forwards
schema_editor.create_model(model)
File "/home/jimmy/lib/python3.6/django/db/backends/base/schema.py", line 324, in create_model
self.execute(sql, params or None)
File "/home/jimmy/lib/python3.6/django/db/backends/base/schema.py", line 142, in execute
cursor.execute(sql, params)
File "/home/jimmy/lib/python3.6/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/jimmy/lib/python3.6/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/jimmy/lib/python3.6/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/jimmy/lib/python3.6/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/jimmy/lib/python3.6/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "profiles_accentcolor" already exists
Looks like i have to run python manage.py migrate --fake-initial to ignore initial migrations.
I am facing a very very strange situation with my Django (in general). I'm using Django 2.2 and Python 3.6.7.
Every single time I create a new project, using:
django-admin startproject myproject
and trying to migrate it, I got this error :
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying admin.0004_auto_20190630_1438... OK
Applying admin.0005_auto_20190630_1441...Traceback (most recent call last):
File "C:\Dev\Django\myproject\manage.py", line 21, in <module>
main()
File "C:\Dev\Django\myproject\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\commands\migrate.py", line 234,
in handle
fake_initial=fake_initial,
File "C:\Dev\Django\Env\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 "C:\Dev\Django\Env\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 "C:\Dev\Django\Env\lib\site-packages\django\db\migrations\executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Dev\Django\Env\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 "C:\Dev\Django\Env\lib\site-packages\django\db\migrations\operations\fields.py", line 249, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\Dev\Django\Env\lib\site-packages\django\db\backends\sqlite3\schema.py", line 137, in alter_field
super().alter_field(model, old_field, new_field, strict=strict)
File "C:\Dev\Django\Env\lib\site-packages\django\db\backends\base\schema.py", line 507, in alter_field
new_db_params = new_field.db_parameters(connection=self.connection)
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 966, in db_parameters
return {"type": self.db_type(connection), "check": self.db_check(connection)}
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 963, in db_type
return self.target_field.rel_db_type(connection=connection)
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 878, in target_field
return self.foreign_related_fields[0]
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 632, in foreign_related_fields
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 619, in related_fields
self._related_fields = self.resolve_related_fields()
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 604, in resolve_related_fields
raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'Users.user' cannot be resolved
this occurs everytime I try to migrate all my projects, even all old projects.
Is this some kind of django bug? or did I configure it improperly? I also use the default django settings (without even touching anything).
I messed up by this error. I cannot do any migrations to all my projects.
I have uninstalled django and reinstalled it back, but nothing changed, I got the same error.
A few moments ago I created a custom user model (AbstractBaseUser) in my project. And it was running perfectly. But I when I try to input data to any model in the admin panel, I got error FOREIGN KEY constraint failed (whereas I had only one model, AbstractBaseUser model). I didn't know what to do with that, And I deleted that project.
Afterwards, I created a new project (for learning purposes), and trying migrate it, this critical serious error appeared.
Do guys have any solution to overcome this? Please help me out of this problem
django-cms: When i tried to perform python manage.py migrate in postgresql, it is returning a TypeError but it is not giving any error in sqlite3.
This is my full traceback:
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/.virtualenvs/pmvp/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/vagrant/.virtualenvs/pmvp/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/.virtualenvs/pmvp/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/vagrant/.virtualenvs/pmvp/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/vagrant/.virtualenvs/pmvp/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/home/vagrant/.virtualenvs/pmvp/lib/python3.6/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 "/home/vagrant/.virtualenvs/pmvp/lib/python3.6/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 "/home/vagrant/.virtualenvs/pmvp/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/vagrant/.virtualenvs/pmvp/lib/python3.6/site-packages/cms/migrations/0019_set_pagenode.py", line 68, in apply
connection.introspection.get_table_description(connection.cursor(), 'cms_page')
File "/home/vagrant/.virtualenvs/pmvp/lib/python3.6/site-packages/django/db/backends/postgresql/introspection.py", line 87, in get_table_description
)) for line in cursor.description
File "/home/vagrant/.virtualenvs/pmvp/lib/python3.6/site-packages/django/db/backends/postgresql/introspection.py", line 87, in <listcomp>
)) for line in cursor.description
TypeError: sequence index must be integer, not 'slice'
Can anyone help me out?
This is a compatibility issue with psycopg.
The error will go after installing an older version of psycopg2.
pip install psycopg2==2.7.7
https://github.com/divio/django-cms/issues/6666
I have a model with a foreign key field. I want to give the foreign key a related name. However, migration fails because of the following error:
IndexError: list index out of range
I'm using Django==1.10.5
Database backend is PostgreSQL
models.py Before/After migrations
Before:
class Contest_participants(models.Model):
contest = models.ForeignKey(Contest)
After:
class Contest_participants(models.Model):
contest = models.ForeignKey(Contest, related_name='contests')
The makemigrations command works fine, but the migrate command fails with the above noted error.
Complete Traceback Error:
Running migrations:
Applying teams.0013_auto_20171031_1225...Traceback (most recent call last):
File "manage.py", line 19, in <module>
execute_from_command_line(sys.argv)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/home/aps/Documents/neuron/venv/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 "/home/aps/Documents/neuron/venv/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 "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/aps/Documents/neuron/venv/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 "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/migrations/operations/fields.py", line 204, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 495, in alter_field
old_db_params, new_db_params, strict)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/backends/postgresql/schema.py", line 117, in _alter_field
new_db_params, strict,
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 504, in _alter_field
fk_names = self._constraint_names(model, [old_field.column], foreign_key=True)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 931, in _constraint_names
constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/backends/postgresql/introspection.py", line 178, in get_constraints
"foreign_key": tuple(used_cols[0].split(".", 1)) if kind.lower() == "foreign key" else None,
IndexError: list index out of range
EDIT: Migrations
class Migration(migrations.Migration):
dependencies = [
('teams', '0012_auto_20170904_1524'),
]
operations = [
migrations.AlterField(
model_name='contest_participants',
name='contest',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contests', to='contest.Contest'),
),
]
So I changed some models and the data structure changed dramatically and made a migration fail. I cleared out the tables that were affected in the database, deleted all the migration files and then tried to migrate again.
It made migrations for all the tables (even the ones that I left behind in the database) and when I try to migrate I get this error:
Operations to perform:
Apply all migrations: study
Running migrations:
Rendering model states... DONE
Applying study.0001_initial...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-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/dist-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/dist-packages/django/db/migrations/executor.py", line 148, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python2.7/dist-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/dist-packages/django/db/migrations/operations/models.py", line 59, in database_forwards
schema_editor.create_model(model)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 286, in create_model
self.execute(sql, params or None)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 111, in execute
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "study_language" already exists
If I go into the migration files and delete the spots where it is trying to migrate an existing table, I get this error...
Operations to perform:
Apply all migrations: study
Running migrations:
Rendering model states... DONE
Applying study.0001_initial...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-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/dist-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/dist-packages/django/db/migrations/executor.py", line 148, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python2.7/dist-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/dist-packages/django/db/migrations/operations/models.py", line 59, in database_forwards
schema_editor.create_model(model)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 236, in create_model
definition, extra_params = self.column_sql(model, field)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 135, in column_sql
db_params = field.db_parameters(connection=self.connection)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 2003, in db_parameters
return {"type": self.db_type(connection), "check": []}
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 1994, in db_type
rel_field = self.related_field
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 1897, in related_field
return self.foreign_related_fields[0]
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 1631, in foreign_related_fields
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 1618, in related_fields
self._related_fields = self.resolve_related_fields()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 1603, in resolve_related_fields
raise ValueError('Related model %r cannot be resolved' % self.rel.to)
ValueError: Related model u'study.Language' cannot be resolved
How can I get this to work without deleting all the tables I left behind in the db?
What worked for me is that I commented out all of the migrations that were not in the db in models.py. I then cleaned the migration folder again and ran the command...
$ python manage.py makemigrations
$ python manage.py migrate appname --fake-initial
Which went smoothly and then I uncommented the models I wanted to add to the db and ran a normal migration...
$ python manage.py makemigrations
$ python manage.py migrate
Everything went smoothly