开发者

MySQLDB code to create wordpress DB tables

I need to create wordpress databases using mysqldb connected to a mysql server but using the SQLAlchemy code. The SQL for the table is as follows:

CREATE TABLE IF NOT EXISTS `wp_links` (
  `link_id` bigint(20) unsigned NOT NULL auto_increment,
  `link_url` varchar(255) NOT NULL default '',
  `link_name` varchar(255) NOT NULL default '',
  `link_image` varchar(255) NOT NULL default '',
  `link_target` varchar(25) NOT NULL default '',
  `link_description` varchar(255) NOT NULL default '',
  `link_visible` varchar(20) NOT NULL default 'Y',
  `link_owner` bigint(20) unsigned NOT NULL default '1',
  `link_rating` int(11) NOT NULL default '0',
  `link_updated` datetime NOT NULL default '0000-00-00 00:00:00',
  `link_rel` varchar(255) NOT NULL default '',
  `link_notes` mediumtext NOT NULL,
  `link_rss` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`link_id`),
  KEY `link_visible` (`link_visible`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;

This is the python code that I wrote to do the same thing:

wp_links = []#links table
wp_links.append (Table ('wp_links', metadata, Column ('link_id', BIGINT(20, unsigned=True),nullable=False, primary_key=True),
                        Column('link_url', VARCHAR(255), nullable=False, server_default=''),
                        Column('link_name', VARCHAR(255), nullable=False, server_default=''),
                        Column('link_image', VARCHAR(255), nullable=False, server_default=''),
                        Column('link_target', VARCHAR(255), nullable=False, server_default=''),
                        Column('link_description', VARCHAR(255), nullable=False, server_default=''),
                        Column('link_visible', 开发者_开发知识库VARCHAR(20), key='link_visible', nullable=False, server_default='Y'),
                        Column('link_owner', BIGINT(20, unsigned=True), nullable=False, server_default='1'),
                        Column('link_rating', INTEGER(11), nullable=False, server_default='0'),
                        Column('link_updated', DATETIME(), nullable=False, server_default='0000-00-00 00:00:00'),
                        Column('link_rel', VARCHAR(255), nullable=False, server_default=''),
                        Column('link_notes', MEDIUMTEXT(), nullable=False),
                        Column('link_rss', VARCHAR(255), nullable=False, server_default='')))

Which translates to the following SQL:

CREATE TABLE IF NOT EXISTS `wp_links` (
  `link_id` bigint(20) unsigned NOT NULL auto_increment,
  `link_url` varchar(255) NOT NULL default '',
  `link_name` varchar(255) NOT NULL default '',
  `link_image` varchar(255) NOT NULL default '',
  `link_target` varchar(255) NOT NULL default '',
  `link_description` varchar(255) NOT NULL default '',
  `link_visible` varchar(20) NOT NULL default 'Y',
  `link_owner` bigint(20) unsigned NOT NULL default '1',
  `link_rating` int(11) NOT NULL default '0',
  `link_updated` datetime NOT NULL default '0000-00-00 00:00:00',
  `link_rel` varchar(255) NOT NULL default '',
  `link_notes` mediumtext NOT NULL,
  `link_rss` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`link_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Note the difference, the line “KEY link_visible (link_visible)” is not present. How do I correct my Python code to make them identical?


Looking at the MYSQL documentation:

KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY can also be specified as just KEY when given in a column definition. This was implemented for compatibility with other database systems.

so therefore I would look at

http://www.sqlalchemy.org/docs/core/schema.html#indexes

Indexes can be created anonymously (using an auto-generated name ix_) for a single column using the inline index keyword on Column

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜