"default" is the Python side default.  The server side default is 
"server_default":

for column in metadata.tables['component'].columns:
    print "%s: %s %s" % (column.name, column.type, column.server_default.arg
                                if column.server_default else None)



On Mar 25, 2013, at 1:57 PM, Roy Smith <r...@panix.com> wrote:

> 
> On Mar 25, 2013, at 1:20 PM, Michael Bayer wrote:
> 
>> MySQL reflects from the "SHOW CREATE TABLE" output, what does that say in 
>> this case ?
> 
> 
> mysql> show create table component;
> +-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
> | Table     | Create Table                                                    
>                                                                               
>                                                                               
>                                                                               
>                                                                               
>                                                                               
>                                                                               
>                                                                               
>                                                                               
>                                                                               
>                                                            |
> +-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
> | component | CREATE TABLE `component` (
>   `id` int(11) NOT NULL,
>   `comp_type_id` int(11) NOT NULL,
>   `active_status_code` varchar(1) NOT NULL,
>   `title` varchar(255) NOT NULL,
>   `duration` varchar(10) NOT NULL,
>   `release_date` date DEFAULT NULL,
>   `seq_number` int(11) NOT NULL,
>   `amg_id` varchar(255) NOT NULL DEFAULT '',
>   `isrc` varchar(12) NOT NULL DEFAULT '',
>   `parental_advisory` tinyint(1) NOT NULL DEFAULT '0',
>   `item_number` int(11) NOT NULL DEFAULT '0',
>   `comp_code` varchar(255) NOT NULL DEFAULT '',
>   `cover_art` tinyint(1) NOT NULL DEFAULT '0',
>   `disk_number` int(11) NOT NULL DEFAULT '0',
>   `label_id` int(11) NOT NULL DEFAULT '0',
>   `muze_id` varchar(255) NOT NULL DEFAULT '',
>   `upc` varchar(255) NOT NULL DEFAULT '',
>   PRIMARY KEY (`id`),
>   KEY `seq_number_idx` (`seq_number`)
> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
> +-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
> 1 row in set (0.01 sec)
> 
> 
> 
> 
> 
>> 
>> 
>> On Mar 25, 2013, at 12:57 PM, Roy Smith <r...@panix.com> wrote:
>> 
>>> Server version: 5.1.63-log MySQL Community Server (GPL)
>>> SQLAlchemy==0.8.0
>>> 
>>> I've got a table which has defaults on some columns.  When I discover the 
>>> table, I get the column names and types, but not the defaults.  What am I 
>>> doing wrong?
>>> 
>>> mysql> describe component;
>>> +--------------------+--------------+------+-----+---------+-------+
>>> | Field              | Type         | Null | Key | Default | Extra |
>>> +--------------------+--------------+------+-----+---------+-------+
>>> | id                 | int(11)      | NO   | PRI | NULL    |       |
>>> | comp_type_id       | int(11)      | NO   |     | NULL    |       |
>>> | active_status_code | varchar(1)   | NO   |     | NULL    |       |
>>> | title              | varchar(255) | NO   |     | NULL    |       |
>>> | duration           | varchar(10)  | NO   |     | NULL    |       |
>>> | release_date       | date         | YES  |     | NULL    |       |
>>> | seq_number         | int(11)      | NO   | MUL | NULL    |       |
>>> | amg_id             | varchar(255) | NO   |     |         |       |
>>> | isrc               | varchar(12)  | NO   |     |         |       |
>>> | parental_advisory  | tinyint(1)   | NO   |     | 0       |       |
>>> | item_number        | int(11)      | NO   |     | 0       |       |
>>> | comp_code          | varchar(255) | NO   |     |         |       |
>>> | cover_art          | tinyint(1)   | NO   |     | 0       |       |
>>> | disk_number        | int(11)      | NO   |     | 0       |       |
>>> | label_id           | int(11)      | NO   |     | 0       |       |
>>> | muze_id            | varchar(255) | NO   |     |         |       |
>>> | upc                | varchar(255) | NO   |     |         |       |
>>> +--------------------+--------------+------+-----+---------+-------+
>>> 
>>> from sqlalchemy.schema import MetaData
>>> credentials = {...}
>>> url = "mysql://{user}:{password}@{host}/{database}".format(**credentials)
>>> metadata = MetaData(url)
>>> metadata.reflect()
>>> for column in metadata.tables['component'].columns:
>>>     print "%s: %s %s" % (column.name, column.type, column.default)
>>> 
>>> prints:
>>> 
>>> id: INTEGER(11) None
>>> comp_type_id: INTEGER(11) None
>>> active_status_code: VARCHAR(1) None
>>> title: VARCHAR(255) None
>>> duration: VARCHAR(10) None
>>> release_date: DATE None
>>> seq_number: INTEGER(11) None
>>> amg_id: VARCHAR(255) None
>>> isrc: VARCHAR(12) None
>>> parental_advisory: TINYINT(1) None
>>> item_number: INTEGER(11) None
>>> comp_code: VARCHAR(255) None
>>> cover_art: TINYINT(1) None
>>> disk_number: INTEGER(11) None
>>> label_id: INTEGER(11) None
>>> muze_id: VARCHAR(255) None
>>> upc: VARCHAR(255) None
>>> 
>>> 
>>> 
>>> -- 
>>> You received this message because you are subscribed to the Google Groups 
>>> "sqlalchemy" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to sqlalchemy+unsubscr...@googlegroups.com.
>>> To post to this group, send email to sqlalchemy@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to sqlalchemy+unsubscr...@googlegroups.com.
>> To post to this group, send email to sqlalchemy@googlegroups.com.
>> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
> 
> 
> ---
> Roy Smith
> r...@panix.com
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to