2015-04-10 8 views
9

Sto cercando di usare admin.LogEntry oggetti durante una datamigration su Django 1.7"Nessuna applicazione installata con etichetta" admin "" in esecuzione migrazione Django. L'applicazione è installata correttamente

Il 'django.contrib.admin' applicazione è quotata INSTALLED_APPS.

Sul guscio, funziona:

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

Ma durante la migrazione, non riesce:

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

Fails come questo:

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

Utilizzando un debugger, ho avuto che l''admin' non è installato:

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'] 

PERCHÉ ??

+2

Non eseguire comandi da 'django-admin' - usano' manage.py', che imposta il modulo impostazioni in modo esplicito. –

+0

Provato usando 'manage.py'. Stesso risultato – alanjds

+0

... in ogni caso, DJANGO_SETTINGS_MODULE è impostato correttamente sull'ambiente – alanjds

risposta

9

Non conosco la causa esatta di ciò. Dovrà scavare nel codice sorgente. ma per ora una soluzione alternativa è aggiungere ('admin', 'name_of_last_migration_in_admin_app') alle dipendenze e le migrazioni andranno bene.

+0

Per la migrazione tra app, è logico che sia necessaria una dipendenza esplicita. In caso contrario, le migrazioni in esecuzione su un database vuoto in ordine alfabetico fallirebbero. –

1

Il Django doc rende chiaro:

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().

Codice esempio:

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), 
    ] 
Problemi correlati