Ошибка отношение уже существует django

I’m trying to set up the tables for a new django project (that is, the tables do NOT already exist in the database); the django version is 1.7 and the db back end is PostgreSQL. The name of the project is crud. Results of migration attempt follow:

python manage.py makemigrations crud

Migrations for 'crud':
  0001_initial.py:
    - Create model AddressPoint
    - Create model CrudPermission
    - Create model CrudUser
    - Create model LDAPGroup
    - Create model LogEntry
    - Add field ldap_groups to cruduser
    - Alter unique_together for crudpermission (1 constraint(s))

python manage.py migrate crud

Operations to perform:
  Apply all migrations: crud
Running migrations:
  Applying crud.0001_initial...Traceback (most recent call last):
  File "manage.py", line 18, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, 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 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 161, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 68, in migrate
    self.apply_migration(migration, fake=fake)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 102, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/migration.py", line 108, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/operations/models.py", line 36, in database_forwards
    schema_editor.create_model(model)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/schema.py", line 262, in create_model
    self.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/schema.py", line 103, in execute
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 82, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 66, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, 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 66, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "crud_crudpermission" already exists

Some highlights from the migration file:

dependencies = [
    ('auth', '0001_initial'),
    ('contenttypes', '0001_initial'),
]
    migrations.CreateModel(
        name='CrudPermission',
        fields=[
            ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
            ('_created_by', models.CharField(default=b'', max_length=64, null=True, editable=False, blank=True)),
            ('_last_updated_by', models.CharField(default=b'', max_length=64, null=True, editable=False, blank=True)),
            ('_created', models.DateTimeField(null=True, editable=False, blank=True)),
            ('_last_updated', models.DateTimeField(null=True, editable=False, blank=True)),
            ('domain', models.CharField(max_length=32, choices=[(b'town', b'Town'), (b'boe', b'BOE'), (b'police', b'Police')])),
            ('ldap_group', models.CharField(max_length=128, verbose_name=b'LDAP group')),
            ('can_add', models.BooleanField(default=False, verbose_name=b'add')),
            ('can_change', models.BooleanField(default=False, verbose_name=b'change')),
            ('restrict_change_to_own', models.BooleanField(default=False)),
            ('can_delete', models.BooleanField(default=False, verbose_name=b'delete')),
            ('restrict_delete_to_own', models.BooleanField(default=False)),
            ('models', models.ManyToManyField(to='contenttypes.ContentType', null=True, blank=True)),
        ],
        options={
            'verbose_name': 'CRUD permission',
        },
        bases=(models.Model,),
    ),
    migrations.AlterUniqueTogether(
        name='crudpermission',
        unique_together=set([('ldap_group', 'can_add', 'can_change', 'can_delete', 'domain')]),
    )

,

The crud app is not meant to actually do anything, but I use it another app, so when I try migrate from that app, I trigger the above problem.

I’ve found other examples on the web of people with similar issues, but none of their cases seem to apply because

  1. The problem affects an entire relation, not just one column
  2. I am not using multiple inheritance.

Where should I look next to find the underlying problem?

Background:
After adding djangoratings to my project, I tried running

django-admin.py schemamigration djangoratings --initial 
--settings=myapp.settings.local 

which resulted in an unknown command error for schemamigration.
I tried to resolve this error by adding my project directory to the PYTHONPATH (I’m using virtualenv and virtualenvwrapper).
This resolved the unknown command error for schemamigration, but I think I specified one directory above my project directory for the PYTHONPATH and when the initial migration was run for djangoratings, it complained about something to do with whoosh (which I am using in my project). I changed the PYTHONPATH directory and tried running

django-admin.py schemamigration djangoratings --initial 
--settings=myapp.settings.local

again. Then I ran the migrate command. This is when I received the error:

django.db.utils.DatabaseError: relation "djangoratings_vote" already exists

I tried migrating all the way back using:

django-admin.py migrate djangoratings zero --settings=myapp.settings.local
Running migrations for djangoratings:
- Migrating backwards to zero state.
< djangoratings:0006_add_cookies
< djangoratings:0005_add_exclusions
< djangoratings:0004_rethink_recommendations
< djangoratings:0003_add_correlations
< djangoratings:0002_add_mean_and_stddev
< djangoratings:0001_initial

and then running —initial again, but the same error occurred after performing the migrate command.

I looked at the list of tables in my database and didn’t see any for djangoratings_vote.

My current migrations listing for djangoratings is as follows:

0001_initial.py                   0006_add_cookies.py
0001_initial.pyc                  0006_add_cookies.pyc
0002_add_mean_and_stddev.py       0007_initial.py
0002_add_mean_and_stddev.pyc      0007_initial.pyc
0003_add_correlations.py          0008_initial.py
0003_add_correlations.pyc         0008_initial.pyc
0004_rethink_recommendations.py   0009_initial.py
0004_rethink_recommendations.pyc  0009_initial.pyc
0005_add_exclusions.py            __init__.py
0005_add_exclusions.pyc           __init__.pyc

How can I resolve the relation «djangoratings_vote» already exists error? Preferably using South?

The error message django.db.utils.ProgrammingError: relation already exists in Python with Django indicates that the database table you are trying to create already exists. This error occurs when you run a Django migration that creates a table with the same name as an existing table. Here are a few methods you can use to resolve the issue:

Method 1: Drop the existing table and recreate it

To fix the django.db.utils.ProgrammingError: relation already exists error, you can drop the existing table and recreate it. Here are the steps to do so:

  1. Open your Django project and go to the app where the table exists.

  2. Open the models.py file and find the model for the table that is causing the error.

  3. Add the following code to the model:

class Meta:
    managed = False
  1. Run the following command in your terminal to drop the table:

This will open the database shell.

  1. In the database shell, run the following command to drop the table:

Replace <table_name> with the name of the table causing the error.

  1. Exit the database shell by typing \q and pressing Enter.

  2. Run the following commands to create the table:

python manage.py makemigrations
python manage.py migrate

This will create the table with the changes made to the model.

Here’s an example of how the model should look like after adding the Meta class:

class MyModel(models.Model):
    # fields

    class Meta:
        managed = False

By setting managed to False, Django will not manage the table, allowing you to drop and recreate it manually.

Note: Dropping a table will delete all data in it. Make sure to back up your data before doing this.

Method 2: Rename the existing table and recreate it with a different name

To fix the django.db.utils.ProgrammingError: relation already exists error in Python, you can rename the existing table and recreate it with a different name. Here are the steps to do this:

  1. Open your Python shell or terminal.
  2. Import the necessary modules:
from django.db import connection
from django.core.management import call_command
  1. Rename the existing table by executing the following SQL command:
with connection.cursor() as cursor:
    cursor.execute("ALTER TABLE table_name RENAME TO new_table_name")
  1. Recreate the table with a different name using the migrate command:
call_command('makemigrations', 'app_name')
call_command('migrate', '--fake-initial')
  1. Verify that the new table has been created successfully:
with connection.cursor() as cursor:
    cursor.execute("SELECT * FROM new_table_name")
    rows = cursor.fetchall()
    print(rows)

Here is the full code example:

from django.db import connection
from django.core.management import call_command

with connection.cursor() as cursor:
    cursor.execute("ALTER TABLE table_name RENAME TO new_table_name")

call_command('makemigrations', 'app_name')
call_command('migrate', '--fake-initial')

with connection.cursor() as cursor:
    cursor.execute("SELECT * FROM new_table_name")
    rows = cursor.fetchall()
    print(rows)

This should fix the django.db.utils.ProgrammingError: relation already exists error by renaming the existing table and recreating it with a different name.

Method 3: Delete the migration file and run the migrations again

To fix the django.db.utils.ProgrammingError: relation already exists error in Django, you can try deleting the migration file and running the migrations again. Here are the steps to do this:

  1. Delete the migration files for the app that is causing the error. You can find these files in the app/migrations/ directory.
$ rm app/migrations/*.py
$ rm app/migrations/*.pyc
  1. Drop the existing database tables for the app. You can do this using the following command:
python manage.py migrate app zero
  1. Recreate the initial migration file for the app.
python manage.py makemigrations app
  1. Run the migrations again.

By following these steps, you should be able to fix the django.db.utils.ProgrammingError: relation already exists error in Django.

Method 4: Use the --fake option with the python manage.py migrate command

To fix the django.db.utils.ProgrammingError: relation already exists error in Python Django, you can use the --fake option with the python manage.py migrate command. Here are the steps to do it:

  1. First, make sure that the database is up-to-date by running the python manage.py makemigrations command.

  2. Then, run the python manage.py migrate --fake command to mark all migrations as applied without actually running them. This will prevent the error from occurring.

Here is an example code snippet:

python manage.py makemigrations
python manage.py migrate --fake

That’s it! This should fix the django.db.utils.ProgrammingError: relation already exists error in Python Django.

Я пытаюсь настроить таблицы для нового проекта django (то есть таблицы НЕ уже существуют в базе данных); версия django — 1.7, а конец db — PostgreSQL. Название проекта красное. Результаты попытки миграции:

python manage.py makemigrations crud

Migrations for 'crud':
  0001_initial.py:
    - Create model AddressPoint
    - Create model CrudPermission
    - Create model CrudUser
    - Create model LDAPGroup
    - Create model LogEntry
    - Add field ldap_groups to cruduser
    - Alter unique_together for crudpermission (1 constraint(s))

python manage.py migrate crud

Operations to perform:
  Apply all migrations: crud
Running migrations:
  Applying crud.0001_initial...Traceback (most recent call last):
  File "manage.py", line 18, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, 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 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 161, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 68, in migrate
    self.apply_migration(migration, fake=fake)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 102, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/migration.py", line 108, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/operations/models.py", line 36, in database_forwards
    schema_editor.create_model(model)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/schema.py", line 262, in create_model
    self.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/schema.py", line 103, in execute
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 82, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 66, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, 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 66, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "crud_crudpermission" already exists

Некоторые основные моменты из файла миграции:

dependencies = [
    ('auth', '0001_initial'),
    ('contenttypes', '0001_initial'),
]
    migrations.CreateModel(
        name='CrudPermission',
        fields=[
            ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
            ('_created_by', models.CharField(default=b'', max_length=64, null=True, editable=False, blank=True)),
            ('_last_updated_by', models.CharField(default=b'', max_length=64, null=True, editable=False, blank=True)),
            ('_created', models.DateTimeField(null=True, editable=False, blank=True)),
            ('_last_updated', models.DateTimeField(null=True, editable=False, blank=True)),
            ('domain', models.CharField(max_length=32, choices=[(b'town', b'Town'), (b'boe', b'BOE'), (b'police', b'Police')])),
            ('ldap_group', models.CharField(max_length=128, verbose_name=b'LDAP group')),
            ('can_add', models.BooleanField(default=False, verbose_name=b'add')),
            ('can_change', models.BooleanField(default=False, verbose_name=b'change')),
            ('restrict_change_to_own', models.BooleanField(default=False)),
            ('can_delete', models.BooleanField(default=False, verbose_name=b'delete')),
            ('restrict_delete_to_own', models.BooleanField(default=False)),
            ('models', models.ManyToManyField(to='contenttypes.ContentType', null=True, blank=True)),
        ],
        options={
            'verbose_name': 'CRUD permission',
        },
        bases=(models.Model,),
    ),
    migrations.AlterUniqueTogether(
        name='crudpermission',
        unique_together=set([('ldap_group', 'can_add', 'can_change', 'can_delete', 'domain')]),
    )

Приложение crud не предназначено, чтобы на самом деле ничего делать, но я использую его в другом приложении, поэтому, когда я пытаюсь выполнить миграцию из этого приложения, я запускаю вышеупомянутую проблему.

Я нашел другие примеры в Интернете людей с подобными проблемами, но ни один из их случаев не применяется, потому что

  • Проблема затрагивает целое отношение, а не только один столбец
  • Я не использую множественное наследование.

Где я должен искать, чтобы найти основную проблему?

Я пытаюсь настроить таблицы для нового проекта django (то есть таблицы НЕ уже существуют в базе данных); версия django — 1.7, а конец db — PostgreSQL. Название проекта красное. Результаты попытки миграции:

python manage.py makemigrations crud

Migrations for 'crud':
  0001_initial.py:
    - Create model AddressPoint
    - Create model CrudPermission
    - Create model CrudUser
    - Create model LDAPGroup
    - Create model LogEntry
    - Add field ldap_groups to cruduser
    - Alter unique_together for crudpermission (1 constraint(s))

python manage.py migrate crud

Operations to perform:
  Apply all migrations: crud
Running migrations:
  Applying crud.0001_initial...Traceback (most recent call last):
  File "manage.py", line 18, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, 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 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 161, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 68, in migrate
    self.apply_migration(migration, fake=fake)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 102, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/migration.py", line 108, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/operations/models.py", line 36, in database_forwards
    schema_editor.create_model(model)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/schema.py", line 262, in create_model
    self.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/schema.py", line 103, in execute
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 82, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 66, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, 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 66, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "crud_crudpermission" already exists

Некоторые основные моменты из файла миграции:

dependencies = [
    ('auth', '0001_initial'),
    ('contenttypes', '0001_initial'),
]
    migrations.CreateModel(
        name='CrudPermission',
        fields=[
            ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
            ('_created_by', models.CharField(default=b'', max_length=64, null=True, editable=False, blank=True)),
            ('_last_updated_by', models.CharField(default=b'', max_length=64, null=True, editable=False, blank=True)),
            ('_created', models.DateTimeField(null=True, editable=False, blank=True)),
            ('_last_updated', models.DateTimeField(null=True, editable=False, blank=True)),
            ('domain', models.CharField(max_length=32, choices=[(b'town', b'Town'), (b'boe', b'BOE'), (b'police', b'Police')])),
            ('ldap_group', models.CharField(max_length=128, verbose_name=b'LDAP group')),
            ('can_add', models.BooleanField(default=False, verbose_name=b'add')),
            ('can_change', models.BooleanField(default=False, verbose_name=b'change')),
            ('restrict_change_to_own', models.BooleanField(default=False)),
            ('can_delete', models.BooleanField(default=False, verbose_name=b'delete')),
            ('restrict_delete_to_own', models.BooleanField(default=False)),
            ('models', models.ManyToManyField(to='contenttypes.ContentType', null=True, blank=True)),
        ],
        options={
            'verbose_name': 'CRUD permission',
        },
        bases=(models.Model,),
    ),
    migrations.AlterUniqueTogether(
        name='crudpermission',
        unique_together=set([('ldap_group', 'can_add', 'can_change', 'can_delete', 'domain')]),
    )

Приложение crud не предназначено, чтобы на самом деле ничего делать, но я использую его в другом приложении, поэтому, когда я пытаюсь выполнить миграцию из этого приложения, я запускаю вышеупомянутую проблему.

Я нашел другие примеры в Интернете людей с подобными проблемами, но ни один из их случаев не применяется, потому что

  • Проблема затрагивает целое отношение, а не только один столбец
  • Я не использую множественное наследование.

Где я должен искать, чтобы найти основную проблему?

4b9b3361

Ответ 1

Это работает довольно хорошо

./manage.py migrate --fake default

Источник: — https://github.com/nijel/weblate/issues/587

Ответ 2

Сделайте ли python manage.py migrate --fake.

Прочитайте https://docs.djangoproject.com/en/1.9/ref/django-admin/#django-admin-migrate.

Ответ 3

У вас возникла аналогичная проблема, в конечном итоге удаленные все .py файлы в папке миграции (django 1.7 создает один автоматически), после этого отлично сработал.

Ответ 4

Я столкнулся с подобной проблемой, когда добавил пару новых полей в существующую модель. Я использую Django 1.9, который представил --run-syncdb. Запуск manage.py migrate --run-syncdb исправил мои таблицы.

Ответ 5

Я столкнулся с аналогичными проблемами, когда я изменил имя столбца. Я получал ту же ошибку, что упоминался в трассировке стека, заданной с его вопросом.

Вот что я сделал.

Сначала я запускал поддельные миграции. Затем я удалил запись (миграции, которую я хотел запустить) из таблицы django_migrations и снова выполнил миграцию (на этот раз не подделка).

Изменения появились как ожидалось для меня.

надеюсь, что это будет полезно.

Ответ 6

Теперь (я использую Django 1.9) вы можете сделать:

./manage.py [—database DATABASE] —fake [app_label] [имя_переменной]

Таким образом, вы ориентируетесь на проблему с большей точностью, и вы можете подделать только проблемную миграцию в конкретной базе данных.

Итак, глядя на вопрос, вы могли:

./manage.py —database default —fake crud crud.0001_initial

Ответ 7

Django предоставляет --fake-initial которую я нашел эффективной для моего использования. Из миграционной документации Django:

—fake-начальная

Позволяет Django пропускать начальную миграцию приложений, если все таблицы базы данных с именами всех моделей, созданных всеми операциями CreateModel в этой миграции, уже существуют. Этот параметр предназначен для использования при первом запуске миграций для базы данных, в которой ранее использовались миграции. Однако этот параметр не проверяет соответствие схемы базы данных за пределами совпадающих имен таблиц, поэтому его можно использовать только в том случае, если вы уверены, что ваша существующая схема совпадает с записанной при первоначальной миграции.

Для моего использования я только что вытащил проект из системы управления версиями и готовился добавить несколько новых полей модели. Я добавил поля, запустил ./manage.py makemigrations и затем попытался запустить ./manage.py migrate что ./manage.py migrate ошибку, поскольку, как и следовало ожидать, многие поля уже существовали в существующей базе данных.

То, что я должен был сделать, — это запустить makemigrations сразу после makemigrations проекта из управления версиями, чтобы создать снимок состояния существующих моделей. Затем следующим шагом будет запуск ./manage.py migrate --fake-initial.

После этого вы можете добавить и makemigrations migrate > migrate как обычно.

ПРИМЕЧАНИЕ: я не знаю, пропустит ли --fake-initial существующие поля и добавит ли новые. Я решил закомментировать новые поля, которые я создал до этого момента, запустить --fake-initial как будто это было первое, что я сделал после извлечения из системы управления версиями, а затем добавил в обновленные поля в следующей миграции.

Другая связанная с этим документация: https://docs.djangoproject.com/en/dev/topics/migrations/#initial-migrations

Ответ 8

Я нашел и решил конкретный пример этой ошибки в проекте Django 1.10, когда я менял поле внешнего ключа с именем member, чтобы указать на другую таблицу. Я менял это в трех разных моделях, и я ударил эту ошибку на всех из них. В моей первой попытке я переименовал member в member_user и попытался создать новое поле member в качестве внешнего ключа, указывающего на новую таблицу, но это не сработало.

Я обнаружил, что когда я переименовал столбец member, он не изменил имя индекса в форме <app>_<model>_<hash>, и когда я попытался создать новый столбец member, он попытался создать такое же имя индекса, хэш-часть имени была одинаковой.

Я решил проблему, создав новое отношение member_user временно и скопировав данные. Это создало новый индекс с другим хэшем. Затем я удалил member и воссоздал его, указав на новую таблицу, и с этим будущим конфликтующим именем индекса. Как только это было сделано, я выполнил шаг RunPython, чтобы заполнить новый столбец member ссылкой на соответствующую таблицу. Я закончил, добавив миграции RemoveField, чтобы очистить временные столбцы member_user.

Мне пришлось разделить мои миграции на два файла, потому что я получил эту ошибку:

psycopg2.OperationalError: не может ALTER TABLE «<table_name > » потому что он имеет ожидающие события запуска

После создания и копирования данных в member_user мне не удалось удалить member в той же транзакции миграции. Это может быть специфическим ограничением postgres, но его легко решить, создав еще одну транзакцию и перемещая все после создания и копирования member_user во вторую миграцию.

Ответ 9

Я нашел эту проблему в web2pyframework в models/config.py.

+ Изменить

settings.base.migrate = True

в конфигурационном файле

settings.base.migrate = False

Задача решена.

Понравилась статья? Поделить с друзьями:

Интересное по теме:

  • Ошибка отношение не существует sql состояние 42p01
  • Ошибка открытия повер поинт
  • Ошибка отношение не существует postgres
  • Ошибка открытия партитуры sibelius
  • Ошибка отношение users не существует

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии