?
avatar ahamed
ahamed
13 Oct 2020

Problem identified

Previously at Joomla 3 this is possible to do something like-

$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->insert($db->qn('#__myTable'));
$query->columns([$db->qn('title'), $db->qn('text')]);
$query->values($db->q('hello world') . ', ' . $db->q('This is the world'));
$db->setQuery($query);
$db->execute();

But now at Joomla 4, this is not working. It says

Field 'asset_id' doesn't have a default value.

Open questions

So the question is the $db should generate the asset_id and if I am wrong then what is the solution for inserting values for only a few columns?

avatar ahamed ahamed - open - 13 Oct 2020
avatar joomla-cms-bot joomla-cms-bot - change - 13 Oct 2020
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 13 Oct 2020
avatar Bakual
Bakual - comment - 13 Oct 2020

Since #__myTable isn't a core table you would have to know yourself what you messed up there ?

avatar SharkyKZ
SharkyKZ - comment - 13 Oct 2020

MySQL drivers in 4.0 use STRICT_TRANS_TABLES mode. You either have to modify the column to add the default value or pass the value when inserting data.

avatar ahamed
ahamed - comment - 13 Oct 2020

MySQL drivers in 4.0 use STRICT_TRANS_TABLES mode. You either have to modify the column to add the default value or pass the value when inserting data.

Does that mean there are no other alternatives?

avatar Bakual
Bakual - comment - 13 Oct 2020

Does that mean there are no other alternatives?

No, you just need to fix your table (if the column should allow empty inserts) or fix you code to always send the value. Which both is quite easy to do.

avatar ahamed ahamed - change - 14 Oct 2020
Status New Closed
Closed_Date 0000-00-00 00:00:00 2020-10-14 05:49:27
Closed_By ahamed
avatar ahamed ahamed - close - 14 Oct 2020
avatar ahamed
ahamed - comment - 14 Oct 2020

Thanks to everyone. I get the solution.

Add a Comment

Login with GitHub to post a comment