Error performing "migrate" after "pip install --upgrade git+git://github.com/tangentlabs/django-oscar.git"

55 views
Skip to first unread message

shafiqu...@gmail.com

unread,
Jul 7, 2014, 5:02:20 PM7/7/14
to django...@googlegroups.com
I get an error when I run the migrate command:

django-admin.py migrate --settings=....

The error is in the elif line in catalogue:0026_determine_product_structure:

class Migration(DataMigration):

    def forwards(self, orm):
        for product in orm.Product.objects.all():
            if product.parent:
                product.structure = 'child'
            elif product.variants.exists():
                product.structure = 'parent'
            else:
                product.structure = 'standalone'
            product.save()

Here is the stack trace:

Running migrations for catalogue:
 - Migrating forwards to 0026_determine_product_structure.
 > catalogue:0026_determine_product_structure
Error in migration: catalogue:0026_determine_product_structure
Traceback (most recent call last):
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
    ignore_ghosts = ignore_ghosts,
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/south/migration/__init__.py", line 220, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/south/migration/migrators.py", line 254, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/south/migration/migrators.py", line 329, in migrate_many
    result = self.migrate(migration, database)
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/south/migration/migrators.py", line 133, in migrate
    result = self.run(migration, database)
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/south/migration/migrators.py", line 114, in run
    return self.run_migration(migration, database)
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/south/migration/migrators.py", line 84, in run_migration
    migration_function()
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/south/migration/migrators.py", line 60, in <lambda>
    return (lambda: direction(orm))
  File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/oscar/apps/catalogue/migrations/0026_determine_product_structure.py", line 13, in forwards
    elif product.variants.exists():
AttributeError: 'Product' object has no attribute 'variants'

I guess the migration failed to create the variants column in the database. I checked my Postgres database, and indeed it is not present. Can anyone suggest how to fix this?

Thanks,

shafiqu...@gmail.com

unread,
Jul 9, 2014, 2:52:21 PM7/9/14
to django...@googlegroups.com
Solved this- I had to:

1. dumpdata
2. drop all tables in the db
3. syncdb
4. migrate
5. truncate all tables
6. loaddata

I think that after upgrading to the latest development version, it is not enough to run the migrate command from the existing state - the migrations have to be run from the beginning.

Michael Lind Hjulskov

unread,
Jul 10, 2014, 5:27:15 AM7/10/14
to django...@googlegroups.com
thanks for sharing how You solved it :o)

how did You do the loaddata part? 
just curious, cause in a week (or three) I want to update my site to the latest oscar, so I dont waste my time developing things that doent work when 0.8 is released.

Michael

shafiqu...@gmail.com

unread,
Jul 10, 2014, 6:19:13 AM7/10/14
to django...@googlegroups.com, mic...@hjulskov.dk
Hello Michael,

Are you upgrading from 0.7? This is what I did to upgrade from 0.7 to 0.8:

For loaddata, I used the following command:

django-admin.py loaddata [FILENAME.json] --settings=myproject.settings.local --ignorenonexistent

but you might use:

manage.py loaddata FILENAME.json --ignorenonexistent

where FILENAME.json is the output of:

django-admin.py dumpdata = --settings=myproject.settings.local > FILENAME.json

or 

manage.py dumpdata > FILENAME.json

After dumping the data, and then upgrading to the latest dev version, you would:

1. pip uninstall django-oscar
2. pip install git+git://github.com/tangentlabs/django-oscar.git
3. drop all tables in the database. Here is how to do so in postgres:


This command in psql generates the sql commands:

select 'drop table if exists "' || tablename || '" cascade;' from pg_tables;

4. manage.py syncdb --noinput
5. manage.py migrate
6. truncate all data in the tables (but do not drop them). Here is how to do so in postgres:


CREATE OR REPLACE FUNCTION truncate_tables(username IN VARCHAR)
RETURNS void AS $$
DECLARE
    statements CURSOR FOR
        SELECT tablename FROM pg_tables
        WHERE tableowner = username AND schemaname = 'public';
BEGIN
    FOR stmt IN statements LOOP
        EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;';
    END LOOP;
END;
$$ LANGUAGE plpgsql;

usage:
SELECT truncate_tables('MYUSER');

7. manage.py loaddata FILENAME.json --ignorenonexistent

You need the --ignorenonexistent option because 0.8 does not use some attributes that 0.7 does. Let me know how this goes for you and if you need help. 

Michael Lind Hjulskov

unread,
Jul 10, 2014, 7:33:17 AM7/10/14
to django...@googlegroups.com
Hi Shafique

Thanks :o)

Yup 0.7.2 to latest - whenever I feel coucky enough :)
I use Mysql and there isnt any important data in it yet, as the shop hasnt opened yet.
but I want to simulate like it was full of important data, just for the practise.

updating my overridden files/apps
How about the apps/files I have overridden, and apps I added / build on?
I would have to go through all my changes, and correct some of it to fit the new oscar 
I dont know how I should tackle this task the easiest way 

re migrating overridden apps
Should I just delete my migrations or what's the way to tackle the database changes I made? 
I suppose I could just leave the latest migrations and not copy them to my overridden apps, and just run schemamigrate changedapp but wouldnt that mess something up.

I guess its all about choosing a good strategy for the update process and just follow those steps.

shafiqu...@gmail.com

unread,
Jul 10, 2014, 9:16:18 AM7/10/14
to django...@googlegroups.com, mic...@hjulskov.dk
Hello Michael,

Good point about the migrations. I have overriden apps, but I did not change or add to the model attributes (only the model methods) so I did not need to copy the migrations over. I would guess, however, that after you do step 4 (syncdb) you should 

4a. delete the migrations folders in your overriden apps folder
4b. copy the migrations folder from the oscar/apps/ folders over to your overriden apps
4c. run the command ./manage.py schemamigration [APP_NAME] --auto for all your overriden apps

continue with step 5. I think this might work, but I might have it wrong... please let us all know how it goes.

Cheers,

Maik Hoepfel

unread,
Jul 11, 2014, 8:33:39 AM7/11/14
to django...@googlegroups.com
Hi Shafique, hi Michael,

Shafique actually ran into a bug that's been fixed here:
https://github.com/tangentlabs/django-oscar/commit/b22c33476d037dad9430c88488d9a2cda96ea616

It's called bleeding edge for a reason ;) What's your reason for running
against master, Shafique?

Either way, I've updated the documentation for you two on how to handle
migrations. I hope it clarifies the scenarios a bit:
http://django-oscar.readthedocs.org/en/latest/topics/upgrading.html

(If you read this now, RTD might not have built the updated version yet.)

Let me know if any of the above is unclear.

Cheers,

Maik
> --
> https://github.com/tangentlabs/django-oscar
> http://django-oscar.readthedocs.org/en/latest/
> https://twitter.com/django_oscar
> ---
> You received this message because you are subscribed to the Google
> Groups "django-oscar" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-oscar...@googlegroups.com
> <mailto:django-oscar...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-oscar.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-oscar/CAJrCdYAYiTh6Y9RoPJNG%3DMW0VB3gzDVdvGHz3yBq-Cu2Fv86uQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-oscar/CAJrCdYAYiTh6Y9RoPJNG%3DMW0VB3gzDVdvGHz3yBq-Cu2Fv86uQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

shafiqu...@gmail.com

unread,
Jul 11, 2014, 10:18:41 AM7/11/14
to django...@googlegroups.com
Hello Maik,

Thanks for fixing the bug. I'm running against master because I want to use oscar 0.8... and since 0.8 it isn't released yet, I figured I might as well just run against master. I want to use 0.8 because creating the custom shipping method (free for orders over $X) was important for me and easier in 0.8 (I couldn't figure out how to do this in 0.7), and I like that in 0.8 I don't have to customize the related application instance. I realize there is a risk in using the latest master; I home functional tests cover everything.

Cheers,

Reply all
Reply to author
Forward
0 new messages