Django:db_index和makemigrations [英] Django : db_index and makemigrations

查看:703
本文介绍了Django:db_index和makemigrations的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在现有的字段中添加一些我的模型中的db_index。我刚刚向模型添加了 db_index = True

I want to add to existing fields some db_index in my models. I just added db_index=Trueto the model.

我以为我需要运行 python manage.py migrate 将它们应用于数据库。我的问题是没有检测到任何变化,因此没有创建迁移。这是一个正常的行为吗?

I was thinking I would need to run python manage.py migrateto apply them on the database. My issue is that no change is detected thus no migration is created. Is it a normal behavior ?

还是有一个我不知道的具体行为?

Or is there a specific behavior I'm not aware of?

谢谢

推荐答案

如果您对SQL足够了解,您仍然可以使用 RunSQL

If you know enough of SQL, you can still create the migration by hand using RunSQL.

For示例:(使用PostgreSQL语法)

For example: (with PostgreSQL syntax)

class Migration(migrations.Migration):

    dependencies = [
        ('your_app', '0001_initial'), # or last mig
    ]

    operations = [
        migrations.RunSQL("CREATE INDEX my_table_my_column_ind ON my_table (my_colum)"),
    ]

相关:使用Django 1.7创建部分索引

这篇关于Django:db_index和makemigrations的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆