Ansible Failing for Task [edx_django_service : migrate database]

Hi All,

I am finding problem while installing ironwood.master at Ubuntu 16.04. Ansible keep getting failed for task [edx_django_service : migrate database].

{
	"changed": true,
	"cmd": ["make", "migrate"],
	"delta": "0:00:06.715185",
	"end": "2020-03-19 13:53:42.941693",
	"failed": true,
	"rc": 2,
	"start": "2020-03-19 13:53:36.226508",
	"stderr": "Traceback (most recent call last):\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/utils.py\", line 64, in execute\n    return self.cursor.execute(sql, params)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/mysql/base.py\", line 101, in execute\n    return self.cursor.execute(query, args)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 250, in execute\n    self.errorhandler(self, exc, value)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/connections.py\", line 42, in defaulterrorhandler\n    raise errorvalue\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 247, in execute\n    res = self._query(query)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 411, in _query\n    rowcount = self._do_query(q)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 374, in _do_query\n    db.query(q)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/connections.py\", line 270, in query\n    _mysql.connection.query(self, query)\n_mysql_exceptions.OperationalError: (1060, \"Duplicate column name 'changed_by_id'\")\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n  File \"manage.py\", line 15, in <module>\n    execute_from_command_line(sys.argv)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/core/management/__init__.py\", line 364, in execute_from_command_line\n    utility.execute()\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/core/management/__init__.py\", line 356, in execute\n    self.fetch_command(subcommand).run_from_argv(self.argv)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/core/management/base.py\", line 283, in run_from_argv\n    self.execute(*args, **cmd_options)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/core/management/base.py\", line 330, in execute\n    output = self.handle(*args, **options)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/core/management/commands/migrate.py\", line 204, in handle\n    fake_initial=fake_initial,\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/migrations/executor.py\", line 115, in migrate\n    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/migrations/executor.py\", line 145, in _migrate_all_forwards\n    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/migrations/executor.py\", line 244, in apply_migration\n    state = migration.apply(state, schema_editor)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/migrations/migration.py\", line 129, in apply\n    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/migrations/operations/fields.py\", line 88, in database_forwards\n    field,\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/mysql/schema.py\", line 48, in add_field\n    super(DatabaseSchemaEditor, self).add_field(model, field)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/base/schema.py\", line 445, in add_field\n    self.execute(sql, params)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/base/schema.py\", line 136, in execute\n    cursor.execute(sql, params)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/utils.py\", line 64, in execute\n    return self.cursor.execute(sql, params)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/utils.py\", line 94, in __exit__\n    six.reraise(dj_exc_type, dj_exc_value, traceback)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/utils/six.py\", line 685, in reraise\n    raise value.with_traceback(tb)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/utils.py\", line 64, in execute\n    return self.cursor.execute(sql, params)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/mysql/base.py\", line 101, in execute\n    return self.cursor.execute(query, args)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 250, in execute\n    self.errorhandler(self, exc, value)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/connections.py\", line 42, in defaulterrorhandler\n    raise errorvalue\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 247, in execute\n    res = self._query(query)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 411, in _query\n    rowcount = self._do_query(q)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 374, in _do_query\n    db.query(q)\n  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/connections.py\", line 270, in query\n    _mysql.connection.query(self, query)\ndjango.db.utils.OperationalError: (1060, \"Duplicate column name 'changed_by_id'\")\nmake: *** [migrate] Error 1",
	"stderr_lines": ["Traceback (most recent call last):", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/utils.py\", line 64, in execute", "    return self.cursor.execute(sql, params)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/mysql/base.py\", line 101, in execute", "    return self.cursor.execute(query, args)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 250, in execute", "    self.errorhandler(self, exc, value)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/connections.py\", line 42, in defaulterrorhandler", "    raise errorvalue", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 247, in execute", "    res = self._query(query)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 411, in _query", "    rowcount = self._do_query(q)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 374, in _do_query", "    db.query(q)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/connections.py\", line 270, in query", "    _mysql.connection.query(self, query)", "_mysql_exceptions.OperationalError: (1060, \"Duplicate column name 'changed_by_id'\")", "", "The above exception was the direct cause of the following exception:", "", "Traceback (most recent call last):", "  File \"manage.py\", line 15, in <module>", "    execute_from_command_line(sys.argv)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/core/management/__init__.py\", line 364, in execute_from_command_line", "    utility.execute()", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/core/management/__init__.py\", line 356, in execute", "    self.fetch_command(subcommand).run_from_argv(self.argv)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/core/management/base.py\", line 283, in run_from_argv", "    self.execute(*args, **cmd_options)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/core/management/base.py\", line 330, in execute", "    output = self.handle(*args, **options)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/core/management/commands/migrate.py\", line 204, in handle", "    fake_initial=fake_initial,", "  File \"/edx/app/discovery/venvs/discovery/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 \"/edx/app/discovery/venvs/discovery/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 \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/migrations/executor.py\", line 244, in apply_migration", "    state = migration.apply(state, schema_editor)", "  File \"/edx/app/discovery/venvs/discovery/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 \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/migrations/operations/fields.py\", line 88, in database_forwards", "    field,", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/mysql/schema.py\", line 48, in add_field", "    super(DatabaseSchemaEditor, self).add_field(model, field)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/base/schema.py\", line 445, in add_field", "    self.execute(sql, params)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/base/schema.py\", line 136, in execute", "    cursor.execute(sql, params)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/utils.py\", line 64, in execute", "    return self.cursor.execute(sql, params)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/utils.py\", line 94, in __exit__", "    six.reraise(dj_exc_type, dj_exc_value, traceback)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/utils/six.py\", line 685, in reraise", "    raise value.with_traceback(tb)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/utils.py\", line 64, in execute", "    return self.cursor.execute(sql, params)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/django/db/backends/mysql/base.py\", line 101, in execute", "    return self.cursor.execute(query, args)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 250, in execute", "    self.errorhandler(self, exc, value)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/connections.py\", line 42, in defaulterrorhandler", "    raise errorvalue", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 247, in execute", "    res = self._query(query)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 411, in _query", "    rowcount = self._do_query(q)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/cursors.py\", line 374, in _do_query", "    db.query(q)", "  File \"/edx/app/discovery/venvs/discovery/lib/python3.5/site-packages/MySQLdb/connections.py\", line 270, in query", "    _mysql.connection.query(self, query)", "django.db.utils.OperationalError: (1060, \"Duplicate column name 'changed_by_id'\")", "make: *** [migrate] Error 1"],
	"stdout": "python manage.py migrate --noinput\nOperations to perform:\n  Apply all migrations: admin, auth, catalogs, contenttypes, core, course_metadata, django_comments, guardian, ietf_language_tags, journal, publisher, publisher_comments, sessions, sites, social_django, taggit, waffle\nRunning migrations:\n  Applying publisher.0007_auto_20160905_1020...Makefile:59: recipe for target 'migrate' failed",
	"stdout_lines": ["python manage.py migrate --noinput", "Operations to perform:", "  Apply all migrations: admin, auth, catalogs, contenttypes, core, course_metadata, django_comments, guardian, ietf_language_tags, journal, publisher, publisher_comments, sessions, sites, social_django, taggit, waffle", "Running migrations:", "  Applying publisher.0007_auto_20160905_1020...Makefile:59: recipe for target 'migrate' failed"]
}

Thanks,
Waleed

1 Like

Seeing this in the error means django is likely trying to apply a migration that your database has already accounted for. I would compare what that migration is doing to your actual DB schema and see if it makes sense to either reverse the migration and try again or fake the migration and continue on.

1 Like