Skip to main content
Version: 0.7.x

Create Index

To create indexes in database instead of writing IndexCreateStatement manually, you can derive it from Entity using Schema::create_index_from_entity. This method will help you create database indexes defined in Entity.

Below we use Indexes entity to demo its generated SQL statement. You can construct the same statement with IndexCreateStatement.

use sea_orm::{sea_query, tests_cfg::*, Schema};

let builder = db.get_database_backend();
let schema = Schema::new(builder);

let stmts = schema.create_index_from_entity(indexes::Entity);
assert_eq!(stmts.len(), 2);

let idx = sea_query::Index::create()

let idx = sea_query::Index::create()