Can't modify 'updated_at' in my database after adding a column with a migration in Laravel 5.1










3















I am trying to add a new integer "id" column in a table of my database to map every row with an id. In order to do so, I am using a migration in Laravel 5.1. The run() function of the migration is exactly the following:



public function up()

Schema::table('license_keys', function($table)
$table->integer('id_nuevo');
);



The table I am trying to modify is set with default 'updated_at' and 'created_at' timestamps.



I execute the migration and the column is added correctly. I made sure to add the new column in the $fillable variable in my model. The next step in the process is to set the ids correctly, because that column is created with all 0s. In order to do so, I am using a Seeder with the following code:



public function run()

$i=1;
$licenses = LicenseKey::getEveryLicenseKey();
foreach ($licenses as $license)
$license->id_nuevo = $i;
//$license->timestamps = false;
$license->save();
$i++;





But the problem starts here. When I try to update any field of any row with the save() function it gives me the following error:



[IlluminateDatabaseQueryException] 
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 (SQL: update `license_keys` set `id_nuevo` = 1, `updated_at` = 2018-11-15 13:24:11
where `hash_key` = 0...0b)



[PDOException]
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1


But if I set the timestamps to false (commented line in the code), the operation succeeds. Even if I try to manually change the value of the 'updated_at' column in phpMyadmin, it gives me the same error. Can anybody help me with this problem?



The structure of the table is:



CREATE TABLE `license_keys` (
`hash_key` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`user_id` int(10) UNSIGNED NOT NULL,
`plan_id` int(10) UNSIGNED NOT NULL,
`id_nuevo` int(11) NOT NULL,
`max_credits` bigint(20) NOT NULL,
`max_models` int(11) NOT NULL,
`max_model_categories` int(11) NOT NULL,
`max_dictionaries` int(11) NOT NULL,
`max_dictionary_entries` int(11) NOT NULL,
`max_sentiment_models` int(11) NOT NULL,
`max_sentiment_entries` int(11) NOT NULL,
`current_credits` bigint(20) NOT NULL,
`current_requests` bigint(20) NOT NULL,
`last_operation` timestamp NULL DEFAULT NULL,
`total_credits` bigint(20) NOT NULL,
`total_requests` bigint(20) NOT NULL,
`msg_pay_status` varchar(510) COLLATE utf8_unicode_ci NOT NULL,
`start_date` timestamp NULL DEFAULT NULL,
`start_billing_date` timestamp NULL DEFAULT NULL,
`expiration_date` timestamp NULL DEFAULT NULL,
`update_operation` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


And the query I'm trying to execute is:



update `license_keys` set `id_nuevo` = 1, `updated_at` = '2018-11-15 13:24:11' where `hash_key` = '0...0b'


Thanks.










share|improve this question
























  • Can you provide the query you execute and the table structure?

    – Jonathan
    Nov 15 '18 at 13:00











  • Yes, for sure! I edited the post with that information

    – Carlos Fuentes
    Nov 15 '18 at 14:20















3















I am trying to add a new integer "id" column in a table of my database to map every row with an id. In order to do so, I am using a migration in Laravel 5.1. The run() function of the migration is exactly the following:



public function up()

Schema::table('license_keys', function($table)
$table->integer('id_nuevo');
);



The table I am trying to modify is set with default 'updated_at' and 'created_at' timestamps.



I execute the migration and the column is added correctly. I made sure to add the new column in the $fillable variable in my model. The next step in the process is to set the ids correctly, because that column is created with all 0s. In order to do so, I am using a Seeder with the following code:



public function run()

$i=1;
$licenses = LicenseKey::getEveryLicenseKey();
foreach ($licenses as $license)
$license->id_nuevo = $i;
//$license->timestamps = false;
$license->save();
$i++;





But the problem starts here. When I try to update any field of any row with the save() function it gives me the following error:



[IlluminateDatabaseQueryException] 
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 (SQL: update `license_keys` set `id_nuevo` = 1, `updated_at` = 2018-11-15 13:24:11
where `hash_key` = 0...0b)



[PDOException]
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1


But if I set the timestamps to false (commented line in the code), the operation succeeds. Even if I try to manually change the value of the 'updated_at' column in phpMyadmin, it gives me the same error. Can anybody help me with this problem?



The structure of the table is:



CREATE TABLE `license_keys` (
`hash_key` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`user_id` int(10) UNSIGNED NOT NULL,
`plan_id` int(10) UNSIGNED NOT NULL,
`id_nuevo` int(11) NOT NULL,
`max_credits` bigint(20) NOT NULL,
`max_models` int(11) NOT NULL,
`max_model_categories` int(11) NOT NULL,
`max_dictionaries` int(11) NOT NULL,
`max_dictionary_entries` int(11) NOT NULL,
`max_sentiment_models` int(11) NOT NULL,
`max_sentiment_entries` int(11) NOT NULL,
`current_credits` bigint(20) NOT NULL,
`current_requests` bigint(20) NOT NULL,
`last_operation` timestamp NULL DEFAULT NULL,
`total_credits` bigint(20) NOT NULL,
`total_requests` bigint(20) NOT NULL,
`msg_pay_status` varchar(510) COLLATE utf8_unicode_ci NOT NULL,
`start_date` timestamp NULL DEFAULT NULL,
`start_billing_date` timestamp NULL DEFAULT NULL,
`expiration_date` timestamp NULL DEFAULT NULL,
`update_operation` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


And the query I'm trying to execute is:



update `license_keys` set `id_nuevo` = 1, `updated_at` = '2018-11-15 13:24:11' where `hash_key` = '0...0b'


Thanks.










share|improve this question
























  • Can you provide the query you execute and the table structure?

    – Jonathan
    Nov 15 '18 at 13:00











  • Yes, for sure! I edited the post with that information

    – Carlos Fuentes
    Nov 15 '18 at 14:20













3












3








3








I am trying to add a new integer "id" column in a table of my database to map every row with an id. In order to do so, I am using a migration in Laravel 5.1. The run() function of the migration is exactly the following:



public function up()

Schema::table('license_keys', function($table)
$table->integer('id_nuevo');
);



The table I am trying to modify is set with default 'updated_at' and 'created_at' timestamps.



I execute the migration and the column is added correctly. I made sure to add the new column in the $fillable variable in my model. The next step in the process is to set the ids correctly, because that column is created with all 0s. In order to do so, I am using a Seeder with the following code:



public function run()

$i=1;
$licenses = LicenseKey::getEveryLicenseKey();
foreach ($licenses as $license)
$license->id_nuevo = $i;
//$license->timestamps = false;
$license->save();
$i++;





But the problem starts here. When I try to update any field of any row with the save() function it gives me the following error:



[IlluminateDatabaseQueryException] 
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 (SQL: update `license_keys` set `id_nuevo` = 1, `updated_at` = 2018-11-15 13:24:11
where `hash_key` = 0...0b)



[PDOException]
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1


But if I set the timestamps to false (commented line in the code), the operation succeeds. Even if I try to manually change the value of the 'updated_at' column in phpMyadmin, it gives me the same error. Can anybody help me with this problem?



The structure of the table is:



CREATE TABLE `license_keys` (
`hash_key` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`user_id` int(10) UNSIGNED NOT NULL,
`plan_id` int(10) UNSIGNED NOT NULL,
`id_nuevo` int(11) NOT NULL,
`max_credits` bigint(20) NOT NULL,
`max_models` int(11) NOT NULL,
`max_model_categories` int(11) NOT NULL,
`max_dictionaries` int(11) NOT NULL,
`max_dictionary_entries` int(11) NOT NULL,
`max_sentiment_models` int(11) NOT NULL,
`max_sentiment_entries` int(11) NOT NULL,
`current_credits` bigint(20) NOT NULL,
`current_requests` bigint(20) NOT NULL,
`last_operation` timestamp NULL DEFAULT NULL,
`total_credits` bigint(20) NOT NULL,
`total_requests` bigint(20) NOT NULL,
`msg_pay_status` varchar(510) COLLATE utf8_unicode_ci NOT NULL,
`start_date` timestamp NULL DEFAULT NULL,
`start_billing_date` timestamp NULL DEFAULT NULL,
`expiration_date` timestamp NULL DEFAULT NULL,
`update_operation` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


And the query I'm trying to execute is:



update `license_keys` set `id_nuevo` = 1, `updated_at` = '2018-11-15 13:24:11' where `hash_key` = '0...0b'


Thanks.










share|improve this question
















I am trying to add a new integer "id" column in a table of my database to map every row with an id. In order to do so, I am using a migration in Laravel 5.1. The run() function of the migration is exactly the following:



public function up()

Schema::table('license_keys', function($table)
$table->integer('id_nuevo');
);



The table I am trying to modify is set with default 'updated_at' and 'created_at' timestamps.



I execute the migration and the column is added correctly. I made sure to add the new column in the $fillable variable in my model. The next step in the process is to set the ids correctly, because that column is created with all 0s. In order to do so, I am using a Seeder with the following code:



public function run()

$i=1;
$licenses = LicenseKey::getEveryLicenseKey();
foreach ($licenses as $license)
$license->id_nuevo = $i;
//$license->timestamps = false;
$license->save();
$i++;





But the problem starts here. When I try to update any field of any row with the save() function it gives me the following error:



[IlluminateDatabaseQueryException] 
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 (SQL: update `license_keys` set `id_nuevo` = 1, `updated_at` = 2018-11-15 13:24:11
where `hash_key` = 0...0b)



[PDOException]
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1


But if I set the timestamps to false (commented line in the code), the operation succeeds. Even if I try to manually change the value of the 'updated_at' column in phpMyadmin, it gives me the same error. Can anybody help me with this problem?



The structure of the table is:



CREATE TABLE `license_keys` (
`hash_key` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`user_id` int(10) UNSIGNED NOT NULL,
`plan_id` int(10) UNSIGNED NOT NULL,
`id_nuevo` int(11) NOT NULL,
`max_credits` bigint(20) NOT NULL,
`max_models` int(11) NOT NULL,
`max_model_categories` int(11) NOT NULL,
`max_dictionaries` int(11) NOT NULL,
`max_dictionary_entries` int(11) NOT NULL,
`max_sentiment_models` int(11) NOT NULL,
`max_sentiment_entries` int(11) NOT NULL,
`current_credits` bigint(20) NOT NULL,
`current_requests` bigint(20) NOT NULL,
`last_operation` timestamp NULL DEFAULT NULL,
`total_credits` bigint(20) NOT NULL,
`total_requests` bigint(20) NOT NULL,
`msg_pay_status` varchar(510) COLLATE utf8_unicode_ci NOT NULL,
`start_date` timestamp NULL DEFAULT NULL,
`start_billing_date` timestamp NULL DEFAULT NULL,
`expiration_date` timestamp NULL DEFAULT NULL,
`update_operation` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


And the query I'm trying to execute is:



update `license_keys` set `id_nuevo` = 1, `updated_at` = '2018-11-15 13:24:11' where `hash_key` = '0...0b'


Thanks.







php laravel-5.1






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 14:19







Carlos Fuentes

















asked Nov 15 '18 at 12:54









Carlos FuentesCarlos Fuentes

164




164












  • Can you provide the query you execute and the table structure?

    – Jonathan
    Nov 15 '18 at 13:00











  • Yes, for sure! I edited the post with that information

    – Carlos Fuentes
    Nov 15 '18 at 14:20

















  • Can you provide the query you execute and the table structure?

    – Jonathan
    Nov 15 '18 at 13:00











  • Yes, for sure! I edited the post with that information

    – Carlos Fuentes
    Nov 15 '18 at 14:20
















Can you provide the query you execute and the table structure?

– Jonathan
Nov 15 '18 at 13:00





Can you provide the query you execute and the table structure?

– Jonathan
Nov 15 '18 at 13:00













Yes, for sure! I edited the post with that information

– Carlos Fuentes
Nov 15 '18 at 14:20





Yes, for sure! I edited the post with that information

– Carlos Fuentes
Nov 15 '18 at 14:20












1 Answer
1






active

oldest

votes


















1














Try your query without update_at, it will be written automatically



update `license_keys` set `id_nuevo` = 1 where `hash_key` = '0...0b'





share|improve this answer























  • Yes, it works. But the thing is that before the migration, the function save(), worked perfectly, and after, it returns that error. The entire code is full of calls to save(), and they wont work. I can just change the query. I must make that funtion work. But thanks anyway!

    – Carlos Fuentes
    Nov 15 '18 at 14:36











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319962%2fcant-modify-updated-at-in-my-database-after-adding-a-column-with-a-migration%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try your query without update_at, it will be written automatically



update `license_keys` set `id_nuevo` = 1 where `hash_key` = '0...0b'





share|improve this answer























  • Yes, it works. But the thing is that before the migration, the function save(), worked perfectly, and after, it returns that error. The entire code is full of calls to save(), and they wont work. I can just change the query. I must make that funtion work. But thanks anyway!

    – Carlos Fuentes
    Nov 15 '18 at 14:36
















1














Try your query without update_at, it will be written automatically



update `license_keys` set `id_nuevo` = 1 where `hash_key` = '0...0b'





share|improve this answer























  • Yes, it works. But the thing is that before the migration, the function save(), worked perfectly, and after, it returns that error. The entire code is full of calls to save(), and they wont work. I can just change the query. I must make that funtion work. But thanks anyway!

    – Carlos Fuentes
    Nov 15 '18 at 14:36














1












1








1







Try your query without update_at, it will be written automatically



update `license_keys` set `id_nuevo` = 1 where `hash_key` = '0...0b'





share|improve this answer













Try your query without update_at, it will be written automatically



update `license_keys` set `id_nuevo` = 1 where `hash_key` = '0...0b'






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 14:28









Garik KhachanyanGarik Khachanyan

3614




3614












  • Yes, it works. But the thing is that before the migration, the function save(), worked perfectly, and after, it returns that error. The entire code is full of calls to save(), and they wont work. I can just change the query. I must make that funtion work. But thanks anyway!

    – Carlos Fuentes
    Nov 15 '18 at 14:36


















  • Yes, it works. But the thing is that before the migration, the function save(), worked perfectly, and after, it returns that error. The entire code is full of calls to save(), and they wont work. I can just change the query. I must make that funtion work. But thanks anyway!

    – Carlos Fuentes
    Nov 15 '18 at 14:36

















Yes, it works. But the thing is that before the migration, the function save(), worked perfectly, and after, it returns that error. The entire code is full of calls to save(), and they wont work. I can just change the query. I must make that funtion work. But thanks anyway!

– Carlos Fuentes
Nov 15 '18 at 14:36






Yes, it works. But the thing is that before the migration, the function save(), worked perfectly, and after, it returns that error. The entire code is full of calls to save(), and they wont work. I can just change the query. I must make that funtion work. But thanks anyway!

– Carlos Fuentes
Nov 15 '18 at 14:36




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319962%2fcant-modify-updated-at-in-my-database-after-adding-a-column-with-a-migration%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto