Я переносил старый проект, но по какой-то причине миграция всегда не удалась для этого файла, я пытался выполнить только этот файл миграции, все та же ошибка.
Я приложил команду, которую использовал, журналыиз терминала python для команды и журналов из базы данных ниже.
Используемая команда
python3 manage.py migrate content 0037_auto_20180618_1711
Файл миграции
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2018-06-18 17:11
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('content', '0036_trivia_original_description'),
]
operations = [
migrations.AlterField(
model_name='trivia',
name='is_approved',
field=models.CharField(blank=True, max_length=32, null=True),
),
]
Журналы миграцииоперация
> File
> "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py",
> line 65, in execute
> return self.cursor.execute(sql, params) psycopg2.OperationalError: server closed the connection unexpectedly
> This probably means the server terminated abnormally
> before or while processing the request.
>
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last): File
> "/usr/local/lib/python3.5/dist-packages/django/db/migrations/executor.py",
> line 244, in apply_migration
> state = migration.apply(state, schema_editor) File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/migration.py",
> line 129, in apply
> operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File
> "/usr/local/lib/python3.5/dist-packages/django/db/migrations/operations/fields.py",
> line 215, in database_forwards
> schema_editor.alter_field(from_model, from_field, to_field) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py",
> line 514, in alter_field
> old_db_params, new_db_params, strict) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/postgresql/schema.py",
> line 112, in _alter_field
> new_db_params, strict, File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py",
> line 683, in _alter_field
> params, File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py",
> line 120, in execute
> cursor.execute(sql, params) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py",
> line 80, in execute
> return super(CursorDebugWrapper, self).execute(sql, params) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py",
> line 65, in execute
> return self.cursor.execute(sql, params) File "/usr/local/lib/python3.5/dist-packages/django/db/utils.py", line 94,
> in __exit__
> six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/local/lib/python3.5/dist-packages/django/utils/six.py", line
> 685, in reraise
> raise value.with_traceback(tb) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py",
> line 65, in execute
> return self.cursor.execute(sql, params) django.db.utils.OperationalError: server closed the connection
> unexpectedly
> This probably means the server terminated abnormally
> before or while processing the request.
>
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last): File
> "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/base.py",
> line 213, in ensure_connection
> self.connect() File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/base.py",
> line 189, in connect
> self.connection = self.get_new_connection(conn_params) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/postgresql/base.py",
> line 176, in get_new_connection
> connection = Database.connect(**conn_params) File "/usr/local/lib/python3.5/dist-packages/psycopg2/__init__.py", line
> 130, in connect
> conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError: FATAL: the database system is in recovery mode
>
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last): File "manage.py", line 12, in
> <module>
> execute_from_command_line(sys.argv) File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py",
> line 363, in execute_from_command_line
> utility.execute() File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py",
> line 355, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py",
> line 283, in run_from_argv
> self.execute(*args, **cmd_options) File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py",
> line 330, in execute
> output = self.handle(*args, **options) File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/migrate.py",
> line 204, in handle
> fake_initial=fake_initial, File "/usr/local/lib/python3.5/dist-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/local/lib/python3.5/dist-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/local/lib/python3.5/dist-packages/django/db/migrations/executor.py",
> line 244, in apply_migration
> state = migration.apply(state, schema_editor) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py",
> line 95, in __exit__
> self.atomic.__exit__(exc_type, exc_value, traceback) File "/usr/local/lib/python3.5/dist-packages/django/db/transaction.py",
> line 267, in __exit__
> connection.set_autocommit(True) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/base.py",
> line 401, in set_autocommit
> self.ensure_connection() File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/base.py",
> line 213, in ensure_connection
> self.connect() File "/usr/local/lib/python3.5/dist-packages/django/db/utils.py", line 94,
> in __exit__
> six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/local/lib/python3.5/dist-packages/django/utils/six.py", line
> 685, in reraise
> raise value.with_traceback(tb) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/base.py",
> line 213, in ensure_connection
> self.connect() File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/base.py",
> line 189, in connect
> self.connection = self.get_new_connection(conn_params) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/postgresql/base.py",
> line 176, in get_new_connection
> connection = Database.connect(**conn_params) File "/usr/local/lib/python3.5/dist-packages/psycopg2/__init__.py", line
> 130, in connect
> conn = _connect(dsn, connection_factory=connection_factory, **kwasync) django.db.utils.OperationalError: FATAL: the database system is in recovery mode
Журнал в базе данных postgresql выглядит следующим образом
postgres_1 | 2019-01-27 15:19:32.361 UTC [1] LOG: database system is ready to accept connections
postgres_1 | 2019-01-27 16:31:15.062 UTC [1] LOG: server process (PID 100) was terminated by signal 11: Segmentation fault
postgres_1 | 2019-01-27 16:31:15.062 UTC [1] DETAIL: Failed process was running: ALTER TABLE "content_trivia" ALTER COLUMN "is_approved" TYPE varchar(32) USING "is_approved"::varchar(32), ALTER COLUMN "is_approved" DROP NOT NULL
postgres_1 | 2019-01-27 16:31:15.062 UTC [1] LOG: terminating any other active server processes
postgres_1 | 2019-01-27 16:31:15.062 UTC [97] WARNING: terminating connection because of crash of another server process
postgres_1 | 2019-01-27 16:31:15.062 UTC [97] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
postgres_1 | 2019-01-27 16:31:15.062 UTC [97] HINT: In a moment you should be able to reconnect to the database and repeat your command.
postgres_1 | 2019-01-27 16:31:15.063 UTC [101] FATAL: the database system is in recovery mode
postgres_1 | 2019-01-27 16:31:15.064 UTC [1] LOG: all server processes terminated; reinitializing
postgres_1 | 2019-01-27 16:31:15.090 UTC [102] LOG: database system was interrupted; last known up at 2019-01-27 15:19:32 UTC
postgres_1 | 2019-01-27 16:31:15.175 UTC [102] LOG: database system was not properly shut down; automatic recovery in progress
postgres_1 | 2019-01-27 16:31:15.184 UTC [102] LOG: redo starts at 0/1B00C58
postgres_1 | 2019-01-27 16:31:15.184 UTC [102] LOG: invalid record length at 0/1B00C90: wanted 24, got 0
postgres_1 | 2019-01-27 16:31:15.184 UTC [102] LOG: redo done at 0/1B00C58
postgres_1 | 2019-01-27 16:31:15.232 UTC [1] LOG: database system is ready to accept connections
Не уверен, почему не удается выполнить конкретную команду SQL.ALTER TABLE "content_trivia" ALTER COLUMN "is_approved" TYPE varchar(32) USING "is_approved"::varchar(32), ALTER COLUMN "is_approved" DROP NOT NULL