This is the code that I have taken to set up my database for a module, which is called static. I keep getting errors about the database and after troubleshooting for about an hour I decided to post this because I'm desperate to get this working. I need to be able to definte a new node type, and this module is the only way that I see how, and I'm pretty sure it will work, as soon as I get my database table up and running. Anyway, this is my code:
function static_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {static} (
vid int(10) unsigned NOT NULL default '0',
nid int(10) unsigned NOT NULL default '0',
quantity int(10) unsigned NOT NULL default '0',
color varchar (255) NOT NULL default '',
PRIMARY KEY (vid, nid),
KEY 'static_nid' (nid)
)");
}
}
The original code was found here:
http://api.drupal.org/api/5/file/developer/examples/node_example.module
and looks like this:
CREATE TABLE node_example ( vid int(10) unsigned NOT NULL default '0', nid int(10) unsigned NOT NULL default '0', color varchar(255) NOT NULL default '', quantity int(10) unsigned NOT NULL default '0', PRIMARY KEY (vid, nid), KEY `node_example_nid` (nid) )
Please help! Thanks in advance!
Comments
What is your error?
From the MySQL manual...
That might be your problem. If that doesn't fix your problem, you might copy/paste any error messages and let us know what MySQL version you're using.
Manual Page
http://dev.mysql.com/doc/refman/5.1/en/create-table.html
That's the page that will be of interest (if you're using MySQL 5.1).
I thought that the mulitple
I thought that the mulitple PRIMARY KEYs may have caused the error, but that actually has no effect at all. Instead I just took away the Key 'static_nid' (nid) and it worked. I'm not entirely sure why, but it's fixed.
The error just said that I had a syntax error/sql error which was located "around 'static_nid'" and the table wasn't being created.
Thanks for the responses!
-Trevor