Php Can';t修改';更新地址';在Laravel 5.1中添加带有迁移的列后,在我的数据库中
我试图在数据库的一个表中添加一个新的整数“id”列,以映射具有id的每一行。为此,我在Laravel 5.1中使用了迁移。迁移的run()函数如下所示:Php Can';t修改';更新地址';在Laravel 5.1中添加带有迁移的列后,在我的数据库中,php,laravel-5.1,Php,Laravel 5.1,我试图在数据库的一个表中添加一个新的整数“id”列,以映射具有id的每一行。为此,我在Laravel 5.1中使用了迁移。迁移的run()函数如下所示: public function up() { Schema::table('license_keys', function($table) { $table->integer('id_nuevo'); }); } 我试图修改的表设置了默认的“updated_at”和“created_at”时间戳 我执行了
public function up()
{
Schema::table('license_keys', function($table) {
$table->integer('id_nuevo');
});
}
我试图修改的表设置了默认的“updated_at”和“created_at”时间戳
我执行了迁移,并且正确添加了列。我确保在模型中的$fillable变量中添加新列。该过程的下一步是正确设置ID,因为该列是使用所有0创建的。为此,我使用的播种机代码如下:
public function run()
{
$i=1;
$licenses = LicenseKey::getEveryLicenseKey();
foreach ($licenses as $license){
$license->id_nuevo = $i;
//$license->timestamps = false;
$license->save();
$i++;
}
}
但问题从这里开始。当我尝试使用save()函数更新任何行的任何字段时,会出现以下错误:
[Illuminate\Database\QueryException]
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
但是,如果我将时间戳设置为false(代码中的注释行),操作将成功。即使我试图手动更改phpMyadmin中“updated_at”列的值,它也会给我相同的错误。有人能帮我解决这个问题吗
该表的结构如下:
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;
我试图执行的查询是:
update `license_keys` set `id_nuevo` = 1, `updated_at` = '2018-11-15 13:24:11' where `hash_key` = '0...0b'
谢谢。在不更新的情况下尝试您的查询,它将自动写入
update `license_keys` set `id_nuevo` = 1 where `hash_key` = '0...0b'
您能提供您执行的查询和表结构吗?当然可以!我用这些信息编辑了这篇文章是的,很有效。但问题是,在迁移之前,函数save()工作得很好,之后返回该错误。整个代码充满了对save()的调用,它们无法工作。我可以更改查询。我必须让这个功能发挥作用。不过还是要谢谢你!