2015-04-10 2 views
9

I admin.LogEntry Objekte während eines datamigration auf Django 1.7"Keine installierte App mit dem Label 'admin'", auf der die Django-Migration ausgeführt wird. Die App ist korrekt installiert

Die 'django.contrib.admin' App auf INSTALLED_APPS aufgeführt zu verwenden versuchen.

Auf der Schale, es funktioniert:

>>> from django.apps import apps 
>>> apps.get_model('admin', 'LogEntry') 
django.contrib.admin.models.LogEntry 

Aber während der Migration, es scheitert:

def do_it(apps, schema_editor): 
    LogEntry = apps.get_model('admin', 'LogEntry') 

wie diese ausfällt:

django-admin migrate 
(...) 
LookupError: No installed app with label 'admin'. 

einen Debugger verwenden, habe ich dass der 'admin' nicht installiert ist:

ipdb> apps.get_apps() 
[] 
ipdb> apps.all_models.keys() 
['website', 'google', 'allauth', 'twitter', 'busca', 'conteudo', 'django_mobile', 'django_filters', 'videocenter', 'tinymce', 'oferta', 'programacaotv', 'contenttypes', 'suit', 'haystack', 'destaque', 'filer', 'galeria', 'auth', 'facebook', 'paintstore', 'critica', 'disqus', 'fichas', 'omeletop', 'autocomplete_light', 'modelsv1', 'temas', 'django_extensions', 'adv_cache_tag', 'taggit', 'social', 'personalidade'] 

WARUM?

+2

Führen Sie keine Befehle von 'django-admin' - verwenden' manage.py', die Ihre Einstellungen Modul setzt ausdrücklich. –

+0

Versucht mit 'manage.py'. Gleiches Ergebnis. – alanjds

+0

... jedenfalls ist das DJANGO_SETTINGS_MODULE für die Umgebung korrekt eingestellt. – alanjds

Antwort

9

Ich kenne die genaue Ursache dafür nicht. Ich muss mich in den Quellcode einarbeiten. Aber jetzt ist eine Problemumgehung hinzufügen ('admin', 'name_of_last_migration_in_admin_app') zu den Abhängigkeiten und die Migrationen sollen in Ordnung gehen.

+0

Für die Cross-App-Migration ist eine explizite Abhängigkeit sinnvoll. Anderenfalls würden laufende Migrationen auf leere Datenbanken in alphabetischer Reihenfolge fehlschlagen. –

1

Die Django doc macht deutlich:

When writing a RunPython function that uses models from apps other than the one in which the migration is located, the migration’s dependencies attribute should include the latest migration of each app that is involved, otherwise you may get an error similar to: LookupError: No installed app with label 'myappname' when you try to retrieve the model in the RunPython function using apps.get_model().

Code-Beispiel:

class Migration(migrations.Migration): 

    dependencies = [ 
     ('app1', '0001_initial'), 
     # added dependency to enable using models from app2 in move_m1 
     ('app2', '0004_foobar'), 
    ] 

    operations = [ 
     migrations.RunPython(move_m1), 
    ] 
Verwandte Themen