Object representation of a single column. Supports equality and inequality comparison of ColumnSchema.
name is the column name. parent is an instance of TableSchema
Note
ColumnSchema objects are automatically created for you by ColumnSchemaBuilder and loaded under schema.databases[name].tables[name].columns
Note
Attributes key, comment are ignored in __eq__, __neq__ comparisons.
Example
>>> schema.databases['sakila'].tables['rental'].columns.keys()
['rental_id', 'rental_date', 'inventory_id', 'customer_id', 'return_date', 'staff_id', 'last_update']
>>> schema.databases['sakila'].tables['rental'].columns['rental_id'].name
'rental_id'
>>> schema.databases['sakila'].tables['rental'].columns['rental_id'].field
'rental_id'
>>> schema.databases['sakila'].tables['rental'].columns['rental_id'].ordinal_position
1L
>>> schema.databases['sakila'].tables['rental'].columns['rental_id'].type
'INT(11)'
>>> schema.databases['sakila'].tables['staff'].columns['password'].charset
'utf8'
>>> schema.databases['sakila'].tables['staff'].columns['password'].collation
'utf8_bin'
>>> schema.databases['sakila'].tables['rental'].columns['rental_id'].null
False
>>> schema.databases['sakila'].tables['rental'].columns['rental_id'].key
'PRI'
>>> schema.databases['sakila'].tables['rental'].columns['last_update'].default
'CURRENT_TIMESTAMP'
>>> schema.databases['sakila'].tables['rental'].columns['rental_id'].extra
'auto_increment'
>>> schema.databases['sakila'].tables['rental'].columns['rental_id'].comment
''
Generate the SQL to create (ADD) this column.
after is the name(string) of the column this should appear after. If after is None, FIRST is used.
with_comment boolean, add column comment to sql statement
>>> schema.databases['sakila'].tables['rental'].columns['last_update'].create(after="staff_id")
'ADD COLUMN `last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP AFTER `staff_id`'
>>> schema.databases['sakila'].tables['rental'].columns['rental_id'].create()
'ADD COLUMN `rental_id` INT(11) NOT NULL auto_increment FIRST'
Generate the SQL for this column definition.
after is the name(string) of the column this should appear after. If after is None, FIRST is used.
with_comment boolean, add column comment to sql statement
>>> schema.databases['sakila'].tables['rental'].columns['last_update'].define(after="staff_id")
'`last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP AFTER `staff_id`'
>>> schema.databases['sakila'].tables['rental'].columns['rental_id'].define()
'`rental_id` INT(11) NOT NULL auto_increment FIRST'
Generate the SQL to drop this column:
>>> schema.databases['sakila'].tables['rental'].columns['rental_id'].drop()
'DROP COLUMN `rental_id`'
Generate the SQL to modify this column.
after is the name(string) of the column this should appear after. If after is None, FIRST is used.x
with_comment boolean, add column comment to sql statement
>>> schema.databases['sakila'].tables['rental'].columns['customer_id'].define(after="inventory_id")
'`customer_id` SMALLINT(5) UNSIGNED NOT NULL AFTER `inventory_id`'
>>> schema.databases['sakila'].tables['rental'].columns['customer_id'].default = 123
>>> schema.databases['sakila'].tables['rental'].columns['customer_id'].modify(after="inventory_id")
'MODIFY COLUMN `customer_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 123 AFTER `inventory_id`'
Returns a dictionary loaded with all of the columns availale in the table. table must be an instance of TableSchema.
Note
This function is automatically called for you and set to schema.databases[name].tables[name].columns when you create an instance of SchemaObject