openlibhums / janeway

A web-based platform for publishing journals, preprints, conference proceedings, and books
https://janeway.systems/
GNU Affero General Public License v3.0
177 stars 65 forks source link

Migration error when trying to run latest migrations starting from 1.3.2 #761

Closed mdlincoln closed 5 years ago

mdlincoln commented 5 years ago

Last month I'd worked up an instance of Janeway with some mocked-up content in an sqlite DB for a front-end developer to work with. We based it on 36595c06267a8ccf95fcab220ee8bc9b10dceb1d and I was just now testing migrating it up to master. The migrations choked at 0020_journal_is_secure:

journal
 [X] 0001_initial
 [X] 0002_auto_20170711_1203
 [X] 0003_pinnedarticle
 [X] 0004_auto_20170813_1302
 [X] 0005_auto_20171002_1503
 [X] 0006_auto_20171115_1216
 [X] 0007_auto_20180129_2342
 [X] 0008_auto_20180129_2352
 [X] 0007_auto_20180208_1225
 [X] 0009_merge_20180208_1443
 [X] 0010_auto_20180709_1207
 [X] 0010_auto_20180412_1544
 [X] 0011_merge_20180716_1312
 [X] 0012_auto_20180824_1025
 [X] 0013_journal_nav_collections
 [X] 0014_journal_disable_metrics_display
 [X] 0015_auto_20181108_1220
 [X] 0016_journal_full_width_navbar
 [X] 0017_file_fields_for_the_last_time
 [X] 0018_journal_disable_html_downloads
 [X] 0019_journal_view_pdf_button
 [ ] 0020_journal_is_secure
 [ ] 0021_journal_enable_correspondence_authors

Although it doesn't depend explicitly on 0021_journal_enable_correspondence_authors, it looks like the migration code tries to call a column journal_journal.enable_correspondence_authors which isn't introduced to the db until the next migration. Full error below the fold.

Running migrations:
  Applying journal.0020_journal_is_secure...Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such column: journal_journal.enable_correspondence_authors

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 16, in 
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/usr/local/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 "/usr/local/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 "/usr/local/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/usr/local/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 "/usr/local/lib/python3.5/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/vol/janeway/src/journal/migrations/0020_journal_is_secure.py", line 10, in populate_journal_is_secure
    for journal in journals:
  File "/usr/local/lib/python3.5/site-packages/django/db/models/query.py", line 250, in __iter__
    self._fetch_all()
  File "/usr/local/lib/python3.5/site-packages/django/db/models/query.py", line 1121, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/usr/local/lib/python3.5/site-packages/django/db/models/query.py", line 53, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
  File "/usr/local/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 899, in execute_sql
    raise original_exception
  File "/usr/local/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 889, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.5/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such column: journal_journal.enable_correspondence_authors
ajrbyers commented 5 years ago

@mdlincoln we've got an open PR to fix this:

https://github.com/BirkbeckCTP/janeway/pull/753