Skip to content

Add index to a column that did not have an index when created #551

Discussion options

You must be logged in to vote

Following this stackoverflow answer, you are able to create a new index with;

from datetime import datetime
from typing import Dict, Optional

from sqlalchemy import BLOB, Column 
from sqlalchemy import Index # new
from sqlmodel import Field, SQLModel, create_engine

# Table schema when table was created 
class ExperimentConfig(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    variant_name: str
    owner: str
    description: bytes = Field(default=None, sa_column=Column(BLOB))
    timestamp: datetime

expcon_var_name_index = Index('expcon_var_name_index', ExperimentConfig.variant_name) # new

db_url = "sqlite:///database.db" # changed
engine = create…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rfan-debug
Comment options

Answer selected by rfan-debug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants