Update / migration error

14 views
Skip to first unread message

Mark Cooper

unread,
Oct 10, 2015, 11:26:33 AM10/10/15
to Mediathread
Hiya, 

Trying to bring my install up to date, but it's throwing some errors. Any suggestions? 

Thanks! 
Mark 

# After manage.py sycdb 

Running migrations:

  Applying djangosherd.0002_auto_20150327_1417...Traceback (most recent call last):

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

    execute_from_command_line(sys.argv)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line

    utility.execute()

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute

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

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv

    self.execute(*args, **options.__dict__)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute

    output = self.handle(*args, **options)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 161, in handle

    executor.migrate(targets, plan, fake=options.get("fake", False))

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 68, in migrate

    self.apply_migration(migration, fake=fake)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 102, in apply_migration

    migration.apply(project_state, schema_editor)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 108, in apply

    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 37, in database_forwards

    field,

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/backends/schema.py", line 388, in add_field

    self.execute(sql, params)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/backends/schema.py", line 111, in execute

    cursor.execute(sql, params)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute

    return self.cursor.execute(sql, params)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__

    six.reraise(dj_exc_type, dj_exc_value, traceback)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute

    return self.cursor.execute(sql, params)

django.db.utils.ProgrammingError: column "collaboration_id" of relation "djangosherd_discussionindex" already exists


#And a (presumably) corresponding server error:


Internal Server Error: /

Traceback (most recent call last):

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/core/handlers/base.py", line 87, in get_response

   response = middleware_method(request)

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/courseaffils/middleware.py", line 143, in process_request

   decorate_request(request, chosen_course)

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/courseaffils/middleware.py", line 93, in decorate_request

   object_pk=str(course.pk))

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method

   return getattr(self.get_queryset(), name)(*args, **kwargs)

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/db/models/query.py", line 422, in get_or_create

   return self.get(**lookup), False

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/db/models/query.py", line 351, in get

   num = len(clone)

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/db/models/query.py", line 122, in __len__

   self._fetch_all()

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/db/models/query.py", line 966, in _fetch_all

   self._result_cache = list(self.iterator())

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator

   for row in compiler.results_iter():

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 701, in results_iter

   for rows in self.execute_sql(MULTI):

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 787, in execute_sql

   cursor.execute(sql, params)

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute

   return self.cursor.execute(sql, params)

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__

   six.reraise(dj_exc_type, dj_exc_value, traceback)

 File "/var/www/mediathread/ve/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute

   return self.cursor.execute(sql, params)

ProgrammingError: column structuredcollaboration_collaboration.policy_record_id does not exist

LINE 1: ...ructuredcollaboration_collaboration"."object_pk", "structure...

                                                            ^

Susan Dreher

unread,
Oct 10, 2015, 11:30:06 AM10/10/15
to Mediathread
Hi Mark -

You'll need to fake out some migrations as they predate the Django schema migration infrastructure.

./manage.py migrate structuredcollaboration --fake 0001

You may need to do the same for threaded comments and possibly courseaffils.

Cheers,
Susan
--
You received this message because you are subscribed to the Google Groups "Mediathread" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mediathread...@googlegroups.com.
To post to this group, send email to media...@googlegroups.com.
Visit this group at http://groups.google.com/group/mediathread.
For more options, visit https://groups.google.com/d/optout.

Mark Cooper

unread,
Oct 10, 2015, 11:48:46 AM10/10/15
to media...@googlegroups.com
Thanks Susan!

This repeatedly fails at the same point after I say “yes” to this. What am I missing? 

django@MediaThread:/var/www/mediathread$ sudo ./manage.py migrate structuredcollaboration --fake 0001
Operations to perform:
  Target specific migration: 0001_initial, from structuredcollaboration
Running migrations:
  No migrations to apply.
The following content types are stale and need to be deleted:

    assetmgr | supportedsource

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel:


You received this message because you are subscribed to a topic in the Google Groups "Mediathread" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mediathread/Y2xsTuwP58Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mediathread...@googlegroups.com.

Mark Cooper

unread,
Oct 10, 2015, 1:17:18 PM10/10/15
to Mediathread
Just a quick update.: by means of the handy dandy manage.py migrate -l option I was able to find additional unapplied migrations and fake those that seemed to block the process. It now shows that all have been applied. However, I am stuck here. Bogged down, it appears, by stale content types. What's a fella to do? -- Mark

Operations to perform:

  Apply all migrations: (none)

Running migrations:

  No migrations to apply.

The following content types are stale and need to be deleted:


    assetmgr | supportedsource


Any objects related to these content types by a foreign key will also

be deleted. Are you sure you want to delete these content types?

If you're unsure, answer 'no'.


    Type 'yes' to continue, or 'no' to cancel: yes

Traceback (most recent call last):

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

    execute_from_command_line(sys.argv)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line

    utility.execute()

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute

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

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv

    self.execute(*args, **options.__dict__)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute

    output = self.handle(*args, **options)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 165, in handle

    emit_post_migrate_signal(created_models, self.verbosity, self.interactive, connection.alias)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/core/management/sql.py", line 268, in emit_post_migrate_signal

    using=db)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 198, in send

    response = receiver(signal=self, sender=sender, **named)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/contrib/contenttypes/management.py", line 84, in update_contenttypes

    ct.delete()

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/models/base.py", line 738, in delete

    collector.collect([self])

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/models/deletion.py", line 198, in collect

    elif sub_objs:

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/models/query.py", line 145, in __nonzero__

    self._fetch_all()

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/models/query.py", line 966, in _fetch_all

    self._result_cache = list(self.iterator())

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator

    for row in compiler.results_iter():

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 701, in results_iter

    for rows in self.execute_sql(MULTI):

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 787, in execute_sql

    cursor.execute(sql, params)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute

    return self.cursor.execute(sql, params)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__

    six.reraise(dj_exc_type, dj_exc_value, traceback)

  File "/var/www/mediathread/ve/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute

    return self.cursor.execute(sql, params)

django.db.utils.ProgrammingError: column structuredcollaboration_collaboration.policy_record_id does not exist

Susan Dreher

unread,
Oct 10, 2015, 1:54:53 PM10/10/15
to Mediathread
Hi Mark -
What other migrations were faked? Some might have been needed.
Cheers,
Susan

--

Mark Cooper

unread,
Oct 10, 2015, 2:11:59 PM10/10/15
to media...@googlegroups.com
Good thing I kept a list! 

It faked some migrations without my say so. I assume this is anticipated behavior, so I won’t list those, but I could.

I manually faked 
structuredcollaboration.0001
structuredcollaboration.0002_auto_20150509_1801
This allowed 0003_auto_20150509_1914  to migrate

Manually faked
djangosherd.0002_auto_20150327_1417
This allowed 0003_auto_20150721_1435

Manually faked 
projects.0004_auto_20150723_1055 
projects.0005_auto_20150723_1232
This allowed a whole stack of projects migrations to go through, including one produced by makemigrations, which I was instructed to run early on:
  0013_delete_projectversion.py:
    - Delete model ProjectVersion

My interpretation or all of this was that some of the earlier “auto” migrations had been made moot by subsequent changes.

I got the stale content types message with every run. Didn’t matter whether I answered yes or no. 

All best, 
Mark 

You received this message because you are subscribed to a topic in the Google Groups "Mediathread" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mediathread/Y2xsTuwP58Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mediathread...@googlegroups.com.

Susan Dreher

unread,
Oct 10, 2015, 5:09:12 PM10/10/15
to media...@googlegroups.com
Hi Mark -

Just took a quick look: structuredcollaboration.0002_auto_20150509_1801 is the one that renamed policy to policy_record. I'm guessing that's the issue based on this error message: django.db.utils.ProgrammingError: column structuredcollaboration_collaboration.policy_record_id does not exist.

The best way to resolve this is probably to apply the sql directly to the database.

To generate the raw sql:
./manage.py sqlmigrate structuredcollaboration 0002

What error/issue prompted the structuredcollaboration 0002 --fake? 

Cheers,
Susan



Mark Cooper

unread,
Oct 11, 2015, 8:27:53 AM10/11/15
to media...@googlegroups.com
Hi Susan,

Thanks so much for your help with this. I applied the sql successfully (no errors). The same error message— .policy_record_id does not exist — persists. This is the message that initially prompted the structuredcollaboration 0002 fake (oops). 

Any other ideas? I did look through the other migrations I faked without spotting anything that seemed obvious. 

Why does that stale content types message persist?

Best,
Mark

Mark Cooper

unread,
Oct 14, 2015, 9:10:39 AM10/14/15
to Mediathread
Hi again,

Lacking other options, I'm considering scrapping the database and starting again. There isn't all that much that's critical in there. Cautionary advice? 

Thanks,
Mark 

Susan Dreher

unread,
Oct 14, 2015, 9:50:19 AM10/14/15
to Mediathread
Hi Mark - 
I sent you two notes directly -- maybe you didn't receive them? I'm happy to hop on gChat with you today and work this out. Ping me when you're ready.
Cheers,
Susan

--
Reply all
Reply to author
Forward
0 new messages