简体   繁体   中英

Querying django migrations table

How can one query the django_migrations table from a view? For instance(What I have tried and of course not working)

from django.db import migrations

latest_migration = migrations.objects.all().order_by('-applied')[0]

If possible, how should one proceed?

The migration model is defined in django.db.migrations.recorder . So you can should change your example code slightly:

from django.db.migrations.recorder import MigrationRecorder
latest_migration = MigrationRecorder.Migration.objects.order_by('-applied')[0]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM