gpt4 book ai didi

laravel - 如何修复 "Table ' database.teches' does not exist” 错误?

转载 作者:行者123 更新时间:2023-12-05 01:05:52 34 4
gpt4 key购买 nike

不知道为什么 migrate 正在寻找 'teches' 而不是真正的表名 'techs'?
文件:TechsTableSeeder.php

class TechsTableSeeder extends Seeder {

/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();

Tech::create(
[
'name'=>'technology',
'description'=>'...',
'year'=>'2014'
]);

}

}
在 php artisan db:seed --class="TechsTableSeeder"上,我在终端中收到以下错误:

[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table'database.teches' doesn't exist (SQL: insert into teches (name,description, year, updated_at, created_at) values (technology,..., 2014, 2013-12-30 03:23:39, 2013-12-30 03:23:39))


模型 Tech.php 确实存在并且是通过 php artisan generate:model 自动生成的 Tech如下:
class Tech extends Eloquent {
protected $guarded = array();

public static $rules = array();
}

最佳答案

它试图将表名放在复数形式中。

只需添加

protected $table = 'tech';

在您的模型类技术中

关于laravel - 如何修复 "Table ' database.teches' does not exist” 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20832952/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com