Hi,
Your point is completely valid, please open an issue on github to track it.
Jeremy
I am using: qdjango v0.4.0-158-g810b021, mysql 5.5.37 on 64bit Linux--
I am having problems creating/droping tables from database with functions QDjango::createTables(); and QDjango::dropTables();
It seems that those functions create tables in alphabetical order - it does not care for FK dependencies.
If I have table A which has foreign key to table B:
SQL query "CREATE TABLE `A` (`id` integer `B_id` integer NOT NULL, CONSTRAINT `FK_B_id` FOREIGN KEY (`B_id`) REFERENCES `B` (`id`) ON DELETE RESTRICT)"
Then it ends with error likeSQL error QSqlError("1005", "QMYSQL: Unable to execute query", "Can't create table 'DB.A' (errno: 150)")
There is workaround - to run createTables many times (or until there is no error 150).
It would be nice if the createTables() checked for foreign keys first,
from these FK dependencies created list of tables in right order and then created those tables.
You received this message because you are subscribed to the Google Groups "QDjango" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qdjango+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
QList<QByteArray> globalModelOrder = QList<QByteArray>();
bool QDjango::createTables()
{
bool ret = true;
foreach (const QByteArray &name, globalModelOrder)
if (!globalMetaModels[name].createTable())
ret = false;
return ret;
}
bool QDjango::dropTables()
{
bool ret = true;
QList<QByteArray>::iterator it = globalModelOrder.end();
while (it != globalModelOrder.begin()) {
--it;
if (!globalMetaModels[*it].dropTable())
ret = false;
}
return ret;
}
QDjangoMetaModel QDjango::registerModel(const QMetaObject *meta)
{
const QByteArray name = meta->className();
if (!globalMetaModels.contains(name))
{
globalMetaModels.insert(name, QDjangoMetaModel(meta));
globalModelOrder.append(name);
}
return globalMetaModels[name];
}
This is not really a "better solution" since it requires the user to register his models in a specific order..
--