Steve Sloan schrieb:
> I am trying to create tests for a model class that contains a foreign
> key.  When I run the tests that include the use of
> turbogears.testutil.DBTest, the tests fail with the following trace:
> 
> Traceback (most recent call last):
>   File "C:\Python24\lib\site-packages\turbogears-1.0.4.4-py2.4.egg
> \turbogears\testutil.py", line 197
> , in tearDown
>     item.dropTable(ifExists=True)
>   File "c:\python24\lib\site-packages\SQLObject-0.10.0-py2.4.egg
> \sqlobject\main.py", line 1343, in d
> ropTable
>     conn.dropTable(cls.sqlmeta.table, cascade)
>   File "c:\python24\lib\site-packages\SQLObject-0.10.0-py2.4.egg
> \sqlobject\dbconnection.py", line 48
> 3, in dropTable
>     self.query("DROP TABLE %s" % tableName)
>   File "c:\python24\lib\site-packages\SQLObject-0.10.0-py2.4.egg
> \sqlobject\dbconnection.py", line 68
> 2, in query
>     return self._dbConnection._query(self._connection, s)
>   File "c:\python24\lib\site-packages\SQLObject-0.10.0-py2.4.egg
> \sqlobject\dbconnection.py", line 33
> 4, in _query
>     self._executeRetry(conn, conn.cursor(), s)
>   File "c:\python24\lib\site-packages\SQLObject-0.10.0-py2.4.egg
> \sqlobject\mysql\mysqlconnection.py"
> , line 125, in _executeRetry
>     raise IntegrityError(msg)
> IntegrityError: Cannot delete or update a parent row: a foreign key
> constraint fails
> 
> This is obviously because I have the foreign key in my table and MySQL
> won't drop the table.  Is there a work around for to using DBTest in
> my scenario, or do I need to come up with another testing strategy?
> Would using sqlite for testing solve the problem?

You can use ForeignKey("Classname", cascade=True)

to make SO delete child-records for you.

Diez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to