Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration error in Django 1.7 / Ошибка при выполнении миграций в Django 1.7 #43

Open
aderugin opened this issue Dec 10, 2014 · 8 comments
Labels

Comments

@aderugin
Copy link

Здравствуйте.

Столкнулся с проблемой при использовании вашего модуля в своем приложении.
При выполнении инициализирующей миграции вылетает следующая ошибка:
"AttributeError: 'module' object has no attribute 'NewBase'".

Находил на github'е обсуждение аналогичной проблемы (#41), но решение мне не помогло.

Django 1.7.1
Django-geoip 0.5.1

Полный текст ошибки:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/admin/Sites/django/pruma/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/admin/Sites/django/pruma/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/admin/Sites/django/pruma/.venv/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/admin/Sites/django/pruma/.venv/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/Users/admin/Sites/django/pruma/.venv/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 63, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/Users/admin/Sites/django/pruma/.venv/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/Users/admin/Sites/django/pruma/.venv/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
    self.build_graph()
  File "/Users/admin/Sites/django/pruma/.venv/lib/python2.7/site-packages/django/db/migrations/loader.py", line 173, in build_graph
    self.load_disk()
  File "/Users/admin/Sites/django/pruma/.venv/lib/python2.7/site-packages/django/db/migrations/loader.py", line 103, in load_disk
    migration_module = import_module("%s.%s" % (module_name, migration_name))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/admin/Sites/django/pruma/pruma/migrations/0001_initial.py", line 11, in <module>
    class Migration(migrations.Migration):
  File "/Users/admin/Sites/django/pruma/pruma/migrations/0001_initial.py", line 72, in Migration
    bases=(django.db.models.base.NewBase, models.Model),
AttributeError: 'module' object has no attribute 'NewBase'

Все установленные приложения

Django==1.7.1
MySQL-python==1.2.5
Pillow==2.6.1
Unidecode==0.04.16
django-ajax-selects==1.3.5
django-appconf==0.6
django-ckeditor==4.4.6
django-compressor==1.4
django-extensions==1.4.6
django-geoip==0.5.1
django-haystack==2.3.1
django-mptt==0.6.1
django-sphinx==4.0.1
django-ulogin==0.2
mock==1.0.1
psycopg2==2.5.4
requests==2.4.3
six==1.8.0
sphinxit==0.3.2
wsgiref==0.1.2
xapian-haystack==2.0.0

Файл миграции

...
        migrations.CreateModel(
            name='Location',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('is_default', models.BooleanField(default=False, help_text='\u0411\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0435\u0441\u043b\u0438 \u0433\u043e\u0440\u043e\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d', verbose_name='\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e')),
                ('is_active', models.BooleanField(default=True, verbose_name='\u0410\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c')),
                ('name', models.CharField(help_text='\u0415\u043a\u0430\u0442\u0435\u0440\u0438\u043d\u0431\u0443\u0440\u0433, \u0421\u0432\u0435\u0440\u0434\u043b\u043e\u0432\u0441\u043a\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0438 \u0442.\u0434.', unique=True, max_length=128, verbose_name='\u0418\u043c\u044f \u043b\u043e\u043a\u0430\u0446\u0438\u0438')),
                ('phone', models.CharField(default='', max_length=64, verbose_name='\u0422\u0435\u043b\u0435\u0444\u043e\u043d', blank=True)),
                ('email', models.EmailField(default='', max_length=64, verbose_name='Email', blank=True)),
                ('footer_contacts', models.TextField(verbose_name='\u041a\u043e\u043d\u0442\u0430\u043a\u0442\u044b \u0432 \u0444\u0443\u0442\u0435\u0440\u0435', blank=True)),
                ('city', models.ManyToManyField(related_name='location_city', verbose_name='\u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u0433\u043e\u0440\u043e\u0434\u0430\u043c', to='django_geoip.City')),
                ('region', models.ManyToManyField(related_name='location_region', verbose_name='\u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u043c', to='django_geoip.Region')),
                ('site', models.ForeignKey(verbose_name='\u0421\u0430\u0439\u0442', to='sites.Site', help_text='\u0421\u0430\u0439\u0442, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043e\u0442\u043d\u0435\u0441\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u0430\u044f \u043b\u043e\u043a\u0430\u0446\u0438\u044f')),
            ],
            options={
                'verbose_name': '\u041b\u043e\u043a\u0430\u0446\u0438\u044f',
                'verbose_name_plural': '\u041b\u043e\u043a\u0430\u0446\u0438\u0438',
            },
            bases=(django.db.models.base.NewBase, models.Model),
        ),
...
@coagulant
Copy link
Member

А класс модели Location можно посмотреть?

@aderugin
Copy link
Author

class Location(GeoLocationFacade):
    is_default = models.BooleanField(default=False, verbose_name='По умолчанию', help_text='Будет подставляться если город пользователя не найден')
    is_active = models.BooleanField(default=True, verbose_name='Активность')
    name = models.CharField(max_length=128, unique=True, verbose_name='Имя локации', help_text='Екатеринбург, Свердловская область и т.д.')
    site = models.ForeignKey(Site, verbose_name='Сайт', help_text='Сайт, к которому отнесена данная локация')
    city = models.ManyToManyField(City, related_name='location_city', verbose_name='Привязка к городам')
    region = models.ManyToManyField(Region, related_name='location_region', verbose_name='Привязка к областям')
    phone = models.CharField(max_length=64, blank=True, default='', verbose_name='Телефон')
    email = models.EmailField(max_length=64, blank=True, default='',  verbose_name='Email')
    footer_contacts = models.TextField(blank=True, verbose_name='Контакты в футере')

    class Meta:
        verbose_name = 'Локация'
        verbose_name_plural = 'Локации'

    def __str__(self):
        return self.name

    @classmethod
    def get_by_ip_range(cls, ip):
        try:
            ip_range = IpRange.objects.by_ip(ip)
            if ip_range.region:
                return ip_range.region.location_region.get()
            elif ip_range.city:
                return ip_range.city.location_city.get()
            else:
                return Location.get_default_location()
        except:
            return Location.get_default_location()

    @classmethod
    def get_default_location(cls):
        try:
            return cls.objects.get(is_default=True)
        except:
            return None

    @classmethod
    def get_available_locations(cls):
        return cls.objects.all()

@coagulant coagulant added the bug label Dec 10, 2014
@coagulant
Copy link
Member

Workaround is to delete initial migration, change

class Location(GeoLocationFacade):

to

class Location(models.Model):

then create migration once again.

Migrations don't work well with abstract classes I guess.

@aderugin
Copy link
Author

Зависает после команды migrate (ждал минут 15)

@coagulant
Copy link
Member

А на каком месте зависает?

@aderugin
Copy link
Author

Сразу после выполнения команды migrate, при этом ничего не пишет (видимо входит в какой-то замкнутый цикл). На ctrl + c реагирует.

@coagulant
Copy link
Member

Если найдёте, что причина в django-geoip буду рад помочь, а пока информации не хватает. У меня не удалось воспроизвести

@aderugin
Copy link
Author

Проблема с зависанием действительно была не в django-geoip.

От этой ошибки "AttributeError: 'module' object has no attribute 'NewBase'" помог предложенный способ:

Workaround is to delete initial migration, change

class Location(GeoLocationFacade):

to

class Location(models.Model):

then create migration once again.

Migrations don't work well with abstract classes I guess.

@coagulant coagulant reopened this Dec 11, 2014
@futurecolors futurecolors locked and limited conversation to collaborators Dec 11, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants