Modify

Ticket #208 (reopened defect)

Opened 5 years ago

Last modified 4 years ago

Error in auto-migration when deleting a reference to object

Reported by: artem.skvira@… Owned by: andrew
Priority: major Milestone: 0.6
Component: migrations Version: 0.5
Keywords: Cc:

Description

Models layout like this:
class Job:

route = models.ForeignKey?('Route')
...

class Route:

...


When removing Route reference from Job class and running
./manage.py startmigration my_application delete --auto
following exception occurs:

  • Deleted field 'my_application.job.route'

Traceback (most recent call last):

File "./manage.py", line 14, in <module>

execute_manager(settings)

File "/var/lib/python-support/python2.6/django/core/management/init.py", line 340, in execute_manager

utility.execute()

File "/var/lib/python-support/python2.6/django/core/management/init.py", line 295, in execute

self.fetch_command(subcommand).run_from_argv(self.argv)

File "/var/lib/python-support/python2.6/django/core/management/base.py", line 192, in run_from_argv

self.execute(*args, options.dict)

File "/var/lib/python-support/python2.6/django/core/management/base.py", line 219, in execute

output = self.handle(*args, options)

File "/usr/local/lib/python2.6/dist-packages/South-0.5-py2.6.egg/south/management/commands/startmigration.py", line 401, in handle

deps = field_dependencies(field, last_models)

File "/usr/local/lib/python2.6/dist-packages/South-0.5-py2.6.egg/south/management/commands/startmigration.py", line 659, in field_dependencies

depends.update(stub_model_dependencies(field.rel.to, last_models))

File "/usr/local/lib/python2.6/dist-packages/South-0.5-py2.6.egg/south/management/commands/startmigration.py", line 653, in stub_model_dependencies

return field_dependencies(model._meta.pk, last_models)

AttributeError?: 'str' object has no attribute '_meta'

Attachments

0005_bug.py (5.8 KB) - added by anonymous 5 years ago.
failing migration

Change History

comment:1 follow-up: ↓ 3 Changed 5 years ago by andrew

  • Status changed from new to closed
  • Resolution set to worksforme
  • Milestone set to 0.6

I cannot replicate this in the trunk version, so I'll mark as Works For Me.

Changed 5 years ago by anonymous

failing migration

comment:2 Changed 5 years ago by artem.skvira@…

Stack trace

% ./manage.py migrate app_name --merge
Running migrations for app_name:

! Migration (app_name, 0005_customer_add_deleted) should not have been applied before (app_name, 0005_add_driver_and_scheduler_to_job) but was.

  • Migrating forwards to 0006_delete_route.

    app_name: 0005_add_driver_and_scheduler_to_job

<class 'app_name.models.driver'>
<class 'app_name.models.appuser'>
<class 'app_name.models.scheduler'>
<class 'app_name.models.appuser'>
<class 'app_name.models.route'>
<class 'app_name.models.driver'>
<class 'app_name.models.appuser'>
<class 'app_name.models.driver'>
Scheduler
Traceback (most recent call last):

File "./manage.py", line 14, in <module>

execute_manager(settings)

File "/var/lib/python-support/python2.6/django/core/management/init.py", line 340, in execute_manager

utility.execute()

File "/var/lib/python-support/python2.6/django/core/management/init.py", line 295, in execute

self.fetch_command(subcommand).run_from_argv(self.argv)

File "/var/lib/python-support/python2.6/django/core/management/base.py", line 192, in run_from_argv

self.execute(*args, options.dict)

File "/var/lib/python-support/python2.6/django/core/management/base.py", line 219, in execute

output = self.handle(*args, options)

File "/usr/local/lib/python2.6/dist-packages/South-0.6_pre-py2.6.egg/south/management/commands/migrate.py", line 88, in handle

skip = skip,

File "/usr/local/lib/python2.6/dist-packages/South-0.6_pre-py2.6.egg/south/migration.py", line 570, in migrate_app

result = run_forwards(mapp, [mname], fake=fake, db_dry_run=db_dry_run, verbosity=verbosity)

File "/usr/local/lib/python2.6/dist-packages/South-0.6_pre-py2.6.egg/south/migration.py", line 376, in run_forwards

verbosity = verbosity,

File "/usr/local/lib/python2.6/dist-packages/South-0.6_pre-py2.6.egg/south/migration.py", line 319, in run_migrations

runfunc(orm)

File "/home/user/Dropbox/ruw/app_name/migrations/0005_add_driver_and_scheduler_to_job.py", line 20, in forwards

job.scheduler = job.route.scheduler

File "/var/lib/python-support/python2.6/django/db/models/fields/related.py", line 236, in get

other_field = self.field.rel.get_related_field()

File "/var/lib/python-support/python2.6/django/db/models/fields/related.py", line 602, in get_related_field

data = self.to._meta.get_field_by_name(self.field_name)

AttributeError?: 'str' object has no attribute '_meta'

comment:3 in reply to: ↑ 1 Changed 5 years ago by anonymous

Replying to andrew:

I cannot replicate this in the trunk version, so I'll mark as Works For Me.

please re-open

comment:4 follow-up: ↓ 5 Changed 5 years ago by andrew

Please say exactly what version you're using, and I'll reopen it.

comment:5 in reply to: ↑ 4 Changed 5 years ago by anonymous

Replying to andrew:

Please say exactly what version you're using, and I'll reopen it.

I just checked out trunk from github

comment:6 Changed 5 years ago by Art <artem.skvira@…>

it seems to be failing on the assignment:

job.scheduler = job.route.scheduler

I tried to print out all of the job' attributes just before this assignment and it fails with same message when job_source is accessed.

I wonder does it have anything to do with actual data in the DB?

comment:7 Changed 5 years ago by Art <artem.skvira@…>

Oh wow, that's weird.

After I changed Scheduler?, JobSource? to lowercase ie scheduler?, jobsource? everything works.

So I presume that's to do with frozen model, generated by 0.5?

comment:8 Changed 5 years ago by andrew

Yes, there were some issues with the 0.5 frozen models, which is why we've moved to newer ones - however, things should be backwards-compatible, and they always have been for me.

In addition, lower- or upper-case accesses are the same to South, it normalises them all, so no idea why it's suddenly started working.

View

Add a comment

Modify Ticket

Action
as reopened
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.