- changed component to schema
- changed title to create_all() should check for other schema constructs (i.e. indexes, others ?)
- changed milestone to 0.6.xx
- assigned issue to
- marked as enhancement
create_all() should check for other schema constructs (i.e. indexes, others ?)
Issue #1993
new
Demo code:
from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
eng=create_engine('sqlite:///:memory:')
Base = declarative_base(bind=eng)
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
Base.metadata.create_all()
ix=Index('user_by_name', User.name)
Base.metadata.create_all()
print eng.execute('select * from sqlite_master').fetchall()
ix.create()
print eng.execute('select * from sqlite_master').fetchall()
Output:
[u'users', u'users', 2, u'CREATE TABLE users (\n\tid INTEGER NOT NULL, \n\tname VARCHAR, \n\tPRIMARY KEY (id)\n)')]((u'table',)
[u'users', u'users', 2, u'CREATE TABLE users (\n\tid INTEGER NOT NULL, \n\tname VARCHAR, \n\tPRIMARY KEY (id)\n)'), (u'index', u'user_by_name', u'users', 3, u'CREATE INDEX user_by_name ON users (name)')]((u'table',)
Comments (2)
-
repo owner -
repo owner - changed milestone to 1.x.xx
- Log in to comment
I'd like to add this as an option. This because, it adds potentially a lot more SQL calls to a create_all(), and runs the risk of failure if an index has a unique constraint inside which isn't satisfied by the table's current data.
I'd wonder to what degree we are being inconsistent - i.e. are we checking for Sequences that don't exist, other constraints on tables, columns , etc ? We can't go that far since then we're building an incomplete, overly simplistic schema migration tool into create_all().
Also note the 0.6.xx milestone is likely to move into 0.7.xx unless this feature happens to get implemented quickly.