create_all() should check for other schema constructs (i.e. indexes, others ?)

Issue #1993 new
Anonymous created an issue

Demo code:

from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base(bind=eng)
class User(Base):
  __tablename__ = 'users'
  id = Column(Integer, primary_key=True)
  name = Column(String)
print eng.execute('select * from sqlite_master').fetchall()
print eng.execute('select * from sqlite_master').fetchall()


[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)

  1. Michael Bayer repo owner

    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.

  2. Log in to comment