You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by "Christoffer Hammarström (JIRA)" <ji...@apache.org> on 2007/01/12 17:46:27 UTC

[jira] Created: (DDLUTILS-150) Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"

Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                 Key: DDLUTILS-150
                 URL: https://issues.apache.org/jira/browse/DDLUTILS-150
             Project: DdlUtils
          Issue Type: Bug
          Components: Core - MySql
         Environment: MySQL 5.0.20-something, MySQL 5.0.32 on Linux, InnoDB tables.
            Reporter: Christoffer Hammarström
         Assigned To: Thomas Dudziak


I'm trying variations on the following code:

               org.apache.ddlutils.model.Database model = platform.readModelFromDatabase(null);
                Table table = model.findTable("text_docs");
                Column templateNameColumn = table.findColumn("template_id");
                templateNameColumn.setType("VARCHAR");
                platform.alterTables(model,false);

Trying to change any column makes ddlutil try to drop unrelated foreign keys, which in my case fails with the following stack-trace:

org.apache.ddlutils.DatabaseOperationException: Error while executing SQL ALTER TABLE text_docs
    DROP INDEX text_docs_FK_meta_id_meta
	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:331)
	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:573)
	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:507)
        ... snipped my classes ...
Caused by: java.sql.SQLException: Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1289)
	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:309)
	... 33 more

The ddl for the table looks like this:

    <table name="text_docs">
        <column name="meta_id" primaryKey="true" required="true" type="INTEGER" />
        <column name="template_id" required="true" type="INTEGER" />
        <column default="1" name="group_id" required="true" type="INTEGER" />
        <column default="-1" name="default_template_1" required="true" type="INTEGER" />
        <column default="-1" name="default_template_2" required="true" type="INTEGER" />
        <column name="default_template" type="INTEGER" required="false" />
        <foreign-key foreignTable="meta">
            <reference foreign="meta_id" local="meta_id" />
        </foreign-key>
        <foreign-key foreignTable="templates">
            <reference foreign="template_id" local="template_id" />
        </foreign-key>
        <foreign-key foreignTable="templates">
            <reference foreign="template_id" local="default_template" />
        </foreign-key>
    </table>

I'm not sure if ddlutils should be dropping the foreign keys, but it should at least not fail with an error. Could this be because i'm using InnoDB tables?
I've tried both some MySQL 5.0.20 version, and the latest 5.0.32.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Commented: (DDLUTILS-150) Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"

Posted by "Christoffer Hammarström (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DDLUTILS-150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12464722 ] 

Christoffer Hammarström commented on DDLUTILS-150:
--------------------------------------------------

I should add that i also get the error when i try to drop the foreign key first.

> Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DDLUTILS-150
>                 URL: https://issues.apache.org/jira/browse/DDLUTILS-150
>             Project: DdlUtils
>          Issue Type: Bug
>          Components: Core - MySql
>         Environment: MySQL 5.0.20-something, MySQL 5.0.32 on Linux, InnoDB tables.
>            Reporter: Christoffer Hammarström
>         Assigned To: Thomas Dudziak
>         Attachments: DDLUTILS-150.patch
>
>
> I'm trying variations on the following code:
>                org.apache.ddlutils.model.Database model = platform.readModelFromDatabase(null);
>                 Table table = model.findTable("text_docs");
>                 Column templateNameColumn = table.findColumn("template_id");
>                 templateNameColumn.setType("VARCHAR");
>                 platform.alterTables(model,false);
> Trying to change any column makes ddlutil try to drop unrelated foreign keys, which in my case fails with the following stack-trace:
> org.apache.ddlutils.DatabaseOperationException: Error while executing SQL ALTER TABLE text_docs
>     DROP INDEX text_docs_FK_meta_id_meta
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:331)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:573)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:507)
>         ... snipped my classes ...
> Caused by: java.sql.SQLException: Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
> 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
> 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
> 	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1289)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:309)
> 	... 33 more
> The ddl for the table looks like this:
>     <table name="text_docs">
>         <column name="meta_id" primaryKey="true" required="true" type="INTEGER" />
>         <column name="template_id" required="true" type="INTEGER" />
>         <column default="1" name="group_id" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_1" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_2" required="true" type="INTEGER" />
>         <column name="default_template" type="INTEGER" required="false" />
>         <foreign-key foreignTable="meta">
>             <reference foreign="meta_id" local="meta_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="template_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="default_template" />
>         </foreign-key>
>     </table>
> I'm not sure if ddlutils should be dropping the foreign keys, but it should at least not fail with an error. Could this be because i'm using InnoDB tables?
> I've tried both some MySQL 5.0.20 version, and the latest 5.0.32.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Commented: (DDLUTILS-150) Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"

Posted by "Christoffer Hammarström (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DDLUTILS-150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12464258 ] 

Christoffer Hammarström commented on DDLUTILS-150:
--------------------------------------------------

The attached patch fixes the issue for me, though i strongly suspect that it's not that simple.

> Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DDLUTILS-150
>                 URL: https://issues.apache.org/jira/browse/DDLUTILS-150
>             Project: DdlUtils
>          Issue Type: Bug
>          Components: Core - MySql
>         Environment: MySQL 5.0.20-something, MySQL 5.0.32 on Linux, InnoDB tables.
>            Reporter: Christoffer Hammarström
>         Assigned To: Thomas Dudziak
>         Attachments: DDLUTILS-150.patch
>
>
> I'm trying variations on the following code:
>                org.apache.ddlutils.model.Database model = platform.readModelFromDatabase(null);
>                 Table table = model.findTable("text_docs");
>                 Column templateNameColumn = table.findColumn("template_id");
>                 templateNameColumn.setType("VARCHAR");
>                 platform.alterTables(model,false);
> Trying to change any column makes ddlutil try to drop unrelated foreign keys, which in my case fails with the following stack-trace:
> org.apache.ddlutils.DatabaseOperationException: Error while executing SQL ALTER TABLE text_docs
>     DROP INDEX text_docs_FK_meta_id_meta
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:331)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:573)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:507)
>         ... snipped my classes ...
> Caused by: java.sql.SQLException: Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
> 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
> 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
> 	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1289)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:309)
> 	... 33 more
> The ddl for the table looks like this:
>     <table name="text_docs">
>         <column name="meta_id" primaryKey="true" required="true" type="INTEGER" />
>         <column name="template_id" required="true" type="INTEGER" />
>         <column default="1" name="group_id" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_1" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_2" required="true" type="INTEGER" />
>         <column name="default_template" type="INTEGER" required="false" />
>         <foreign-key foreignTable="meta">
>             <reference foreign="meta_id" local="meta_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="template_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="default_template" />
>         </foreign-key>
>     </table>
> I'm not sure if ddlutils should be dropping the foreign keys, but it should at least not fail with an error. Could this be because i'm using InnoDB tables?
> I've tried both some MySQL 5.0.20 version, and the latest 5.0.32.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Commented: (DDLUTILS-150) Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"

Posted by "Christoffer Hammarström (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DDLUTILS-150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12464721 ] 

Christoffer Hammarström commented on DDLUTILS-150:
--------------------------------------------------

No, i don't.

> Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DDLUTILS-150
>                 URL: https://issues.apache.org/jira/browse/DDLUTILS-150
>             Project: DdlUtils
>          Issue Type: Bug
>          Components: Core - MySql
>         Environment: MySQL 5.0.20-something, MySQL 5.0.32 on Linux, InnoDB tables.
>            Reporter: Christoffer Hammarström
>         Assigned To: Thomas Dudziak
>         Attachments: DDLUTILS-150.patch
>
>
> I'm trying variations on the following code:
>                org.apache.ddlutils.model.Database model = platform.readModelFromDatabase(null);
>                 Table table = model.findTable("text_docs");
>                 Column templateNameColumn = table.findColumn("template_id");
>                 templateNameColumn.setType("VARCHAR");
>                 platform.alterTables(model,false);
> Trying to change any column makes ddlutil try to drop unrelated foreign keys, which in my case fails with the following stack-trace:
> org.apache.ddlutils.DatabaseOperationException: Error while executing SQL ALTER TABLE text_docs
>     DROP INDEX text_docs_FK_meta_id_meta
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:331)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:573)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:507)
>         ... snipped my classes ...
> Caused by: java.sql.SQLException: Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
> 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
> 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
> 	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1289)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:309)
> 	... 33 more
> The ddl for the table looks like this:
>     <table name="text_docs">
>         <column name="meta_id" primaryKey="true" required="true" type="INTEGER" />
>         <column name="template_id" required="true" type="INTEGER" />
>         <column default="1" name="group_id" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_1" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_2" required="true" type="INTEGER" />
>         <column name="default_template" type="INTEGER" required="false" />
>         <foreign-key foreignTable="meta">
>             <reference foreign="meta_id" local="meta_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="template_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="default_template" />
>         </foreign-key>
>     </table>
> I'm not sure if ddlutils should be dropping the foreign keys, but it should at least not fail with an error. Could this be because i'm using InnoDB tables?
> I've tried both some MySQL 5.0.20 version, and the latest 5.0.32.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Updated: (DDLUTILS-150) Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"

Posted by "Christoffer Hammarström (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DDLUTILS-150?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christoffer Hammarström updated DDLUTILS-150:
---------------------------------------------

    Attachment: DDLUTILS-150.patch

> Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DDLUTILS-150
>                 URL: https://issues.apache.org/jira/browse/DDLUTILS-150
>             Project: DdlUtils
>          Issue Type: Bug
>          Components: Core - MySql
>         Environment: MySQL 5.0.20-something, MySQL 5.0.32 on Linux, InnoDB tables.
>            Reporter: Christoffer Hammarström
>         Assigned To: Thomas Dudziak
>         Attachments: DDLUTILS-150.patch
>
>
> I'm trying variations on the following code:
>                org.apache.ddlutils.model.Database model = platform.readModelFromDatabase(null);
>                 Table table = model.findTable("text_docs");
>                 Column templateNameColumn = table.findColumn("template_id");
>                 templateNameColumn.setType("VARCHAR");
>                 platform.alterTables(model,false);
> Trying to change any column makes ddlutil try to drop unrelated foreign keys, which in my case fails with the following stack-trace:
> org.apache.ddlutils.DatabaseOperationException: Error while executing SQL ALTER TABLE text_docs
>     DROP INDEX text_docs_FK_meta_id_meta
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:331)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:573)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:507)
>         ... snipped my classes ...
> Caused by: java.sql.SQLException: Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
> 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
> 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
> 	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1289)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:309)
> 	... 33 more
> The ddl for the table looks like this:
>     <table name="text_docs">
>         <column name="meta_id" primaryKey="true" required="true" type="INTEGER" />
>         <column name="template_id" required="true" type="INTEGER" />
>         <column default="1" name="group_id" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_1" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_2" required="true" type="INTEGER" />
>         <column name="default_template" type="INTEGER" required="false" />
>         <foreign-key foreignTable="meta">
>             <reference foreign="meta_id" local="meta_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="template_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="default_template" />
>         </foreign-key>
>     </table>
> I'm not sure if ddlutils should be dropping the foreign keys, but it should at least not fail with an error. Could this be because i'm using InnoDB tables?
> I've tried both some MySQL 5.0.20 version, and the latest 5.0.32.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Commented: (DDLUTILS-150) Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"

Posted by "Christoffer Hammarström (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DDLUTILS-150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12464727 ] 

Christoffer Hammarström commented on DDLUTILS-150:
--------------------------------------------------

That is, the following code gives the same error.

                org.apache.ddlutils.model.Database model = platform.readModelFromDatabase(null);
                Table textDocsTable = model.findTable("text_docs");
                ForeignKey[] foreignKeys = textDocsTable.getForeignKeys();
                for ( ForeignKey foreignKey : foreignKeys ) {
                    textDocsTable.removeForeignKey(foreignKey);
                }
                platform.alterTables(model, false);


> Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DDLUTILS-150
>                 URL: https://issues.apache.org/jira/browse/DDLUTILS-150
>             Project: DdlUtils
>          Issue Type: Bug
>          Components: Core - MySql
>         Environment: MySQL 5.0.20-something, MySQL 5.0.32 on Linux, InnoDB tables.
>            Reporter: Christoffer Hammarström
>         Assigned To: Thomas Dudziak
>         Attachments: DDLUTILS-150.patch
>
>
> I'm trying variations on the following code:
>                org.apache.ddlutils.model.Database model = platform.readModelFromDatabase(null);
>                 Table table = model.findTable("text_docs");
>                 Column templateNameColumn = table.findColumn("template_id");
>                 templateNameColumn.setType("VARCHAR");
>                 platform.alterTables(model,false);
> Trying to change any column makes ddlutil try to drop unrelated foreign keys, which in my case fails with the following stack-trace:
> org.apache.ddlutils.DatabaseOperationException: Error while executing SQL ALTER TABLE text_docs
>     DROP INDEX text_docs_FK_meta_id_meta
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:331)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:573)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:507)
>         ... snipped my classes ...
> Caused by: java.sql.SQLException: Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
> 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
> 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
> 	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1289)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:309)
> 	... 33 more
> The ddl for the table looks like this:
>     <table name="text_docs">
>         <column name="meta_id" primaryKey="true" required="true" type="INTEGER" />
>         <column name="template_id" required="true" type="INTEGER" />
>         <column default="1" name="group_id" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_1" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_2" required="true" type="INTEGER" />
>         <column name="default_template" type="INTEGER" required="false" />
>         <foreign-key foreignTable="meta">
>             <reference foreign="meta_id" local="meta_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="template_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="default_template" />
>         </foreign-key>
>     </table>
> I'm not sure if ddlutils should be dropping the foreign keys, but it should at least not fail with an error. Could this be because i'm using InnoDB tables?
> I've tried both some MySQL 5.0.20 version, and the latest 5.0.32.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Commented: (DDLUTILS-150) Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"

Posted by "Thomas Dudziak (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DDLUTILS-150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12464267 ] 

Thomas Dudziak commented on DDLUTILS-150:
-----------------------------------------

Do you also (before calling alterTables) change the type of the referenced primary key ?

> Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DDLUTILS-150
>                 URL: https://issues.apache.org/jira/browse/DDLUTILS-150
>             Project: DdlUtils
>          Issue Type: Bug
>          Components: Core - MySql
>         Environment: MySQL 5.0.20-something, MySQL 5.0.32 on Linux, InnoDB tables.
>            Reporter: Christoffer Hammarström
>         Assigned To: Thomas Dudziak
>         Attachments: DDLUTILS-150.patch
>
>
> I'm trying variations on the following code:
>                org.apache.ddlutils.model.Database model = platform.readModelFromDatabase(null);
>                 Table table = model.findTable("text_docs");
>                 Column templateNameColumn = table.findColumn("template_id");
>                 templateNameColumn.setType("VARCHAR");
>                 platform.alterTables(model,false);
> Trying to change any column makes ddlutil try to drop unrelated foreign keys, which in my case fails with the following stack-trace:
> org.apache.ddlutils.DatabaseOperationException: Error while executing SQL ALTER TABLE text_docs
>     DROP INDEX text_docs_FK_meta_id_meta
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:331)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:573)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:507)
>         ... snipped my classes ...
> Caused by: java.sql.SQLException: Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
> 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
> 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
> 	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1289)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:309)
> 	... 33 more
> The ddl for the table looks like this:
>     <table name="text_docs">
>         <column name="meta_id" primaryKey="true" required="true" type="INTEGER" />
>         <column name="template_id" required="true" type="INTEGER" />
>         <column default="1" name="group_id" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_1" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_2" required="true" type="INTEGER" />
>         <column name="default_template" type="INTEGER" required="false" />
>         <foreign-key foreignTable="meta">
>             <reference foreign="meta_id" local="meta_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="template_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="default_template" />
>         </foreign-key>
>     </table>
> I'm not sure if ddlutils should be dropping the foreign keys, but it should at least not fail with an error. Could this be because i'm using InnoDB tables?
> I've tried both some MySQL 5.0.20 version, and the latest 5.0.32.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Resolved: (DDLUTILS-150) Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"

Posted by "Thomas Dudziak (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DDLUTILS-150?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Dudziak resolved DDLUTILS-150.
-------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.0

As per MySql documentation (http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html), InnoDB creates an index for the foreign key fields if there is not already one. This index has the same name as the foreign key, and DdlUtils tries to automatically drop this index when the foreign key is dropped. However, if such an index already exists (e.g. if the local foreign key column is the primary key column), then no such index is created and hence the DROP statement fails.
I've changed this to only drop the index if - during reading in the model from the live db - such an index for the foreign key was detected.


> Trying to change a column makes ddlutils want to drop non-related foreign keys which fails with for example "Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists"
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DDLUTILS-150
>                 URL: https://issues.apache.org/jira/browse/DDLUTILS-150
>             Project: DdlUtils
>          Issue Type: Bug
>          Components: Core - MySql
>         Environment: MySQL 5.0.20-something, MySQL 5.0.32 on Linux, InnoDB tables.
>            Reporter: Christoffer Hammarström
>         Assigned To: Thomas Dudziak
>             Fix For: 1.0
>
>         Attachments: DDLUTILS-150.patch
>
>
> I'm trying variations on the following code:
>                org.apache.ddlutils.model.Database model = platform.readModelFromDatabase(null);
>                 Table table = model.findTable("text_docs");
>                 Column templateNameColumn = table.findColumn("template_id");
>                 templateNameColumn.setType("VARCHAR");
>                 platform.alterTables(model,false);
> Trying to change any column makes ddlutil try to drop unrelated foreign keys, which in my case fails with the following stack-trace:
> org.apache.ddlutils.DatabaseOperationException: Error while executing SQL ALTER TABLE text_docs
>     DROP INDEX text_docs_FK_meta_id_meta
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:331)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:573)
> 	at org.apache.ddlutils.platform.PlatformImplBase.alterTables(PlatformImplBase.java:507)
>         ... snipped my classes ...
> Caused by: java.sql.SQLException: Can't DROP 'text_docs_FK_meta_id_meta'; check that column/key exists
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
> 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
> 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
> 	at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
> 	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1289)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
> 	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(PlatformImplBase.java:309)
> 	... 33 more
> The ddl for the table looks like this:
>     <table name="text_docs">
>         <column name="meta_id" primaryKey="true" required="true" type="INTEGER" />
>         <column name="template_id" required="true" type="INTEGER" />
>         <column default="1" name="group_id" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_1" required="true" type="INTEGER" />
>         <column default="-1" name="default_template_2" required="true" type="INTEGER" />
>         <column name="default_template" type="INTEGER" required="false" />
>         <foreign-key foreignTable="meta">
>             <reference foreign="meta_id" local="meta_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="template_id" />
>         </foreign-key>
>         <foreign-key foreignTable="templates">
>             <reference foreign="template_id" local="default_template" />
>         </foreign-key>
>     </table>
> I'm not sure if ddlutils should be dropping the foreign keys, but it should at least not fail with an error. Could this be because i'm using InnoDB tables?
> I've tried both some MySQL 5.0.20 version, and the latest 5.0.32.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.