I cannot get the advpoll_choices table to install. The table was not created during the module installation. It did not get created when update.php was run. I even tried to paste the text of the CREATE table command and run a MySQL query, and that would not create the table.
When I try to run as a query, here is the code I used:
CREATE TABLE advpoll_choices (nid int(10) NOT NULL, label text NOT NULL, vote_offset int(2) unsigned default NULL, writein tinyint NOT NULL default '0', PRIMARY KEY (nid, vote_offset), KEY vote_offset (vote_offset) ) /*!40100 DEFAULT CHARACTER SET utf8 */;
I get this error message: "All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead."
But changing vote_offset to NOT NULL or UNIQUE does not work. I'm not sure what to try next.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | advpoll_choices.patch | 11.68 KB | ChrisKennedy |
| #17 | advpoll_choices.patch | 11.69 KB | ChrisKennedy |
| #13 | advpoll_choices.patch | 11.32 KB | ChrisKennedy |
| #9 | advpoll_vote_offset.patch | 2.03 KB | ChrisKennedy |
| #8 | advpoll_vote_offset.patch | 2.02 KB | ChrisKennedy |
Comments
Comment #1
ChrisKennedy commentedHmm what version of MySQL are you using and what error do you get when you change vote_offset to be NOT NULL?
Comment #2
jimsmith commentedMySQL version 3.23.58
Error message when vote_offset is changed to NOT NULL:
failed : You have an error in your SQL syntax near 'NOT NULL, writein tinyint NOT NULL default '0', PRIMARY KEY (nid, vote_offset), ' at line 1
Comment #3
ChrisKennedy commentedAh, take out the preceding "default" when you change it to "not null".
Comment #4
jimsmith commentedThat fixed the problem. Thank you!
Comment #5
anders.fajerson commentedComment #6
ChrisKennedy commentedWe might as well fix this in the code, as I don't see a good reason to keep "default NULL".
Here's the old MySQL bug for this btw (fixed in more recent versions): http://bugs.mysql.com/bug.php?id=390
I think we can remove that "KEY vote_offset (vote_offset)" also, because if a column is already listed as a primary key it shouldn't need another separate key, no?
Comment #7
anders.fajerson commentedSounds fair to me, even though not really my area.
Comment #8
ChrisKennedy commentedHere's a patch. I tested upgrading and installing from scratch and I didn't get any errors.
Comment #9
ChrisKennedy commentedBah, just noticed an error in the pgsql code.
Comment #10
ChrisKennedy commentedAnd like many areas, we should look to poll.module for comparison: http://cvs.drupal.org/viewvc.py/drupal/drupal/modules/poll/poll.install?...
In this case poll.module has its vote_offset (chorder) as NOT NULL, and does not have a separate index. Also note that each choice has a unique id in core, which is something we should eventually do too (for reordering, etc., esp. with the sweet AHAH drag-and-drop in D6).
Comment #11
ChrisKennedy commentedI realized I should just stop being lazy and implement unique ids for choices. A comprehensive patch is in the works.
Comment #12
anders.fajerson commentedExcellent. Testers are lined up.
Comment #13
ChrisKennedy commentedHere's an initial patch with basic functionality - needs more testing though.
Comment #14
ChrisKennedy commentedThought: should we also rename vote_offset to "order"?
Comment #15
anders.fajerson commented0. Old polls doesn't display the results correctly. I couldn't find the problem but I think it's a display issue, and not a problem with the upgrade path.
1.
(nid, label, vote_offset, writein) VALUES (%d, '%s', %d, 0)- If writein is never anything else than 0, it should be safe to leave it out.2.
db_query('SELECT cid, vote_offset, label, writein- can bedb_query('SELECT *, not sure what is prefered.3.
$form_values['nid'], check_plain(implode(', ', $form_values['promote'])));- usually check_plain is only used on output.4. I prefer {order} instead of {vote_offset}
5. Just an observation: Core uses 'chid' instead of 'cid' (but also prefixes all column names with ch).
I will run the upgrade path on a bigger dataset when this is ready.
Comment #16
ChrisKennedy commentedBtw, D6 just got drag-and-drop reordering: http://drupal.org/node/193076
Comment #17
ChrisKennedy commented0. Ah should be fixed; I needed to update votingapi_cache as well as votingapi_vote for the new choice ids.
1. Double true.
2. Eh I prefer to write em out.
3. I noticed that, but it's a separate issue.
4. I started doing order but I realized it might mess up the SQL since it's probably a reserved word. The D6 reordering patch also renamed that column and they chose weight, so that's what I did here.
5. Yeah that's just because poll.module is old and bad.
Comment #18
anders.fajerson commentedQuick code review, will do some more testing later.
1. Typo, should be
cid int unsigned NOT NULL auto_increment2. I core, when serial is used, this is often used:
cid serial CHECK (cid >= 0)3.
update_sql('ALTER TABLE {advpoll_choices} ADD cid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST')- Double-check use of upper/lower case?Comment #19
ChrisKennedy commented1. & 3. - got it.
2. Yeah I thought about doing that but I couldn't find an example of getting that added in an update function. Since it's optional I would prefer to keep the installs and updates with the same db schema.
Comment #20
anders.fajerson commentedRun the upgrade on a larger dataset and I couldn't see any problems.
Don't forget to bump up the upgrade to 8 (7 just went in), apart from that this is ready. Exciting times in Drupal 6!
Comment #21
ChrisKennedy commentedWoot - http://drupal.org/cvs?commit=90024
Comment #22
ChrisKennedy commentedRight after the commit I realized I forgot about advpoll_convert.module. Fixed now: http://drupal.org/cvs?commit=90031
Comment #23
anders.fajerson commentedOk, cool. The last SQL statement in that row is mixing %d and numbers (1 and 0), extremely minor, but we might as well fix that.
Comment #24
ChrisKennedy commentedWhich way of fixing it do you prefer? I'm ambivalent.
Comment #25
anders.fajerson commentedMe too, that's why I didn't suggest anything :) I search core some days ago and at least saw that they used 0 instead of %d once. But you decide :)
Comment #26
ChrisKennedy commentedBah fine :P 0 it is.
http://drupal.org/cvs?commit=90032
Comment #27
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.