简体   繁体   English

查询django迁移表

[英]Querying django migrations table

How can one query the django_migrations table from a view? 如何从视图中查询django_migrations表? 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 . 迁移模型在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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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