Bug 13563

Summary: Can't migrate from django 1.x to 2.x
Product: [Yocto Project Subprojects] Security Response Tool Reporter: Ross Burton <ross.burton>
Component: GeneralAssignee: David Reyna <david.reyna>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium+    
Version: unspecified   
Target Milestone: 3.2 M1   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Ross Burton 2019-09-30 13:43:29 UTC
If I copy srtool from a django 1.1.23 machine to a django 2.2.3 machine (literally rsync srtool entirely) then on startup the new Django complains about the schema:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, orm, sessions, users
Running migrations:
  Applying auth.0010_alter_group_name_max_length...Traceback (most recent call last):
  File "/home/rburton/Yocto/srtool/lib/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/rburton/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/rburton/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/rburton/.local/lib/python3.5/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/rburton/.local/lib/python3.5/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/home/rburton/.local/lib/python3.5/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/rburton/.local/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 234, in handle
    fake_initial=fake_initial,
  File "/home/rburton/.local/lib/python3.5/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/rburton/.local/lib/python3.5/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/rburton/.local/lib/python3.5/site-packages/django/db/migrations/executor.py", line 247, in apply_migration
    migration_recorded = True
  File "/home/rburton/.local/lib/python3.5/site-packages/django/db/backends/sqlite3/schema.py", line 34, in __exit__
    self.connection.check_constraints()
  File "/home/rburton/.local/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 350, in check_constraints
    bad_row[1], referenced_table_name, referenced_column_name,
django.db.utils.IntegrityError: The row in table 'orm_cvesource' with primary key '127681' has an invalid foreign key: orm_cvesource.cve_id contains a value '-1' that does not have a corresponding value in orm_cve.id.
Failed migrations, aborting system start
Failed start.

django IRC says:

[14:31:29]  <kezabelle>	somewhere you've got -1 as either a value or a default, which isn't a valid value for the FK
[14:38:44]  <kezabelle>	regardless, if the new one is finding problems the old version wasn't, the new version is probably correct 
Comment 1 David Reyna 2019-10-03 14:35:24 UTC
Yes. 

I have a set of patches that I am preparing for SRTool and for Toaster. These are about 5 fundamental changes that have to be done to accommodate Django-2.x.

- David
Comment 2 David Reyna 2019-12-05 16:26:40 UTC
Here is the pending related Toaster patch:

 Toaster: transitioning to Django-2.2 soon [YOCTO #13207]

 http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=dreyna/toaster/django_2_2_13207&id=117fc2dd7dc220c516309477f2cbe2134f1bd5db
Comment 3 David Reyna 2020-06-24 22:32:55 UTC
commit 4dabdbe11ddc47a885c7f8cc6b3f26439d40d77c
commit 5890b72bd68673738b38e67019dadcbcaf643ed8 (Dunfell)