Update: 

It seems the piece which generates the problematic statement is in the 
method migrate_table in dal.py and it currently looks like this: 

'ALTER TABLE %s ADD %s__tmp %s;' % (t, key, tt),
'UPDATE %s SET %s__tmp=%s;' % (t, key, key),
'ALTER TABLE %s DROP %s;' % (t, key),
'ALTER TABLE %s ADD %s %s;' % (t, key, tt),
'UPDATE %s SET %s=%s__tmp;' % (t, key, key),
'ALTER TABLE %s DROP %s__tmp;' % (t, key)

If the table definition specifies UNIQUE, that would be included on the 
first line, like so:

ALTER TABLE auth_user ADD email__tmp VARCHAR(128) NULL UNIQUE;

This fails (at least on MS SQL) as all values are NULL.

The way round that would be to leave out UNIQUE from the first statement, 
and instead add an additional statement to alter the new column AFTER it 
has been populated:

ALTER TABLE auth_user ADD CONSTRAINT  <constraintname> UNIQUE NONCLUSTERED 
([email]);

--------

I think the way to go about this would be to have the capability of 
defining a "post-populate statement", and determine from the table 
definition whether it might needed, and generate it according to the 
database type.

A bit like:
   ....We're doing a migrate, aha, this table has "requires=UNIQUE()" so it 
will need a post_populate_statement for "unique" (which may well be 
database type specific). We won't mention anything about the column being 
unique in the ADD statements for the temp and new tables used to copy the 
values over, instead we'll run the modifying statement after the values 
have been copied and the temp table dropped. 

I can't figure out how the DAL works in enough details to be able to 
suggest a patch for these changes, if my suggestion is even approved.

PS: how integrated is the DAL with other components? The reason I'm even 
trying to upgrade is the first place is because I can't get form.custom to 
work and I know it has been changed in the latest version or trunk. Could I 
upgrade to 2.3.2 but revert the DAL to the old version and temporarily 
avoid this problem?

Thanks.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to