default=0 in Column statement should produce DEFAULT=0 in CREATE TABLE SQL statement

Issue #510 resolved
Former user created an issue

Table('test',meta, Column('Id', Integer, primary_key=True), Column('Name', String(60)), Column('Status', Integer, nullable=False, default=1), ) produces CREATE TABLE test ( "Id" INTEGER NOT NULL, "Name" VARCHAR(60), "Status" INTEGER NOT NULL, PRIMARY KEY ("Id") ); instead of CREATE TABLE test ( "Id" INTEGER NOT NULL, "Name" VARCHAR(60), "Status" INTEGER NOT NULL DEFAULT 1, PRIMARY KEY ("Id") );

Even though the underlying behaviour works, this can lead to big problems if other applications not based on SQLalchemy (shell scripts, C progs) use the same database

Note that I am using sqlite access in this particular case and I did not try MySQL or Pg

Comments (2)

  1. Mike Bayer repo owner

    "default=1" indicates a client side default which will be assigned on the Python side before an INSERT. server side defaults are specified using "PassiveDefault":

    Table('test',meta,
       Column('Id', Integer,primary_key=True),
       Column('Name', String(60)),
        Column('Status', Integer, PassiveDefault(text("1")),
     nullable=False, ),
     )
    

    i did make a modification in the docs in changeset:2413 to clarify the "text" clause (which i think should probably not be necessary but for now it eliminates reading the value as a string literal).

  2. Log in to comment