Hi Derek
Yes if you have a table with records, you first have to create the table
without notnull=True.
Then you insert something into the new field e.g. you could even make it
blank by adding an empty string
>>> db(db.table).update(your_newfield = '' )
Then you can replace notnull=True.
Note the default setting only works on new records being added.
Regards,
David
On Wednesday, 9 May 2012 00:03:11 UTC+1, Derek wrote:
>
> So apparently this is caused because the migration creates this new
> column, (in my case "name__tmp") and adds the new constraints to it, but
> since it's doing it to a database with data in it, the new column defaults
> to having null values. Since the constraint is 'notnull' it fails to create
> it. However, even adding a default didn't seem to help, as I think the
> 'default' is not set at the database level.
>
> On Tuesday, May 8, 2012 3:56:28 PM UTC-7, Derek wrote:
>>
>> Looks like the workaround is adding a "requires=IS_NOT_EMPTY()" so the
>> field definition.
>>
>> On Tuesday, May 8, 2012 3:39:36 PM UTC-7, Derek wrote:
>>>
>>> <class 'pyodbc.ProgrammingError'> ('42000', "[42000] [Microsoft][ODBC
>>> SQL Server Driver][SQL Server]ALTER TABLE only allows columns to be added
>>> that can contain nulls, or have a DEFAULT definition specified, or the
>>> column being added is an identity or timestamp column, or alternatively if
>>> none of the previous conditions are satisfied the table must be empty to
>>> allow addition of this column. Column 'name__tmp' cannot be added to
>>> non-empty table 'customers' because it does not satisfy these conditions.
>>> (4901) (SQLExecDirectW)")
>>>
>>> I had a table that existed previously, but I wanted to add a
>>> 'notnull=True' constraint to it. Apparently, I am not allowed to do that
>>> because I get this error (SQL 2005).
>>>
>>> Is there a workaround? This is 1.99.7.
>>>
>>