error django.db.utils.ProgrammingError:relation" myApp_audiofile"尝试重命名模型

时间:2017-07-29 17:01:27

标签: django django-models django-migrations

我有一个名为AudioFile的模型,它在几个ManyToMany和ManyToOne关系中使用。我尝试了一个简单的重命名迁移(如建议的here

看起来像这样:

from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('myApp', '0004_feedback'),
    ]

    operations = [
        migrations.RenameModel('AudioFile', 'MediaFile')
    ]

但是它没有工作得到一个错误回溯,如下所示:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/Users/mac/.virtualenvs/myVenv/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 "/Users/mac/.virtualenvs/myVenv/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 "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/migrations/operations/models.py", line 369, in database_forwards
    to_field,
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 515, in alter_field
    old_db_params, new_db_params, strict)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/backends/postgresql/schema.py", line 112, in _alter_field
    new_db_params, strict,
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 773, in _alter_field
    self.execute(self._create_fk_sql(model, new_field, "_fk_%(to_table)s_%(to_column)s"))
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 120, in execute
    cursor.execute(sql, params)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 80, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "myApp_audiofile" does not exist

尝试恢复到之前的迁移时,出现以下错误:

Operations to perform:
  Target specific migration: 0004_feedback, from myApp
Running migrations:
  No migrations to apply.
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 186, in handle
    changes = autodetector.changes(graph=executor.loader.graph)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/migrations/autodetector.py", line 47, in changes
    changes = self._detect_changes(convert_apps, graph)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/migrations/autodetector.py", line 133, in _detect_changes
    self.old_apps = self.from_state.concrete_apps
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/migrations/state.py", line 222, in concrete_apps
    self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)
  File "/Users/mac/.virtualenvs/myVenv/lib/python3.6/site-packages/django/db/migrations/state.py", line 295, in __init__
    raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field myApp.Feedback.lesson was declared with a lazy reference to 'myApp.audiofile', but app 'myApp' doesn't provide model 'audiofile'.
The field myApp.Playlist.audio_files was declared with a lazy reference to 'myApp.audiofile', but app 'myApp' doesn't provide model 'audiofile'.
The field myApp.PlaylistOrder.file was declared with a lazy reference to 'myApp.audiofile', but app 'myApp' doesn't provide model 'audiofile'.
The field myApp.Progress.lesson was declared with a lazy reference to 'myApp.audiofile', but app 'myApp' doesn't provide model 'audiofile'.

谁能解释这里发生了什么?重命名模型似乎带来了很多问题。

我已经崩溃到崩溃的地步。并且SQL语句崩溃是:

ALTER TABLE "myApp_playlistorder" ADD CONSTRAINT "myApp_play_file_id_13fdafe4_fk_myApp" FOREIGN KEY ("file_id") REFERENCES "myApp_audiofile" ("id") DEFERRABLE INITIALLY DEFERRED

0 个答案:

没有答案