gpt4 book ai didi

php - Laravel Eloquent 无法确定表

转载 作者:行者123 更新时间:2023-11-29 05:54:11 26 4
gpt4 key购买 nike

我已经创建了一个数据库播种器来播种我在几秒钟前通过迁移创建的表。但是,我在运行播种机时遇到此错误:

In Connection.php line 664:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'trier_taxibus.ca
tegories' doesn't exist (SQL: insert into `categories` (`category`, `update
d_at`, `created_at`) values (ISF, 2018-07-10 14:16:08, 2018-07-10 14:16:08)
)


In Connection.php line 452:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'trier_taxibus.ca
tegories' doesn't exist

SQL 语句对我来说看起来不错,如果我将它复制并粘贴到 PhpMyAdmin,它也能正常工作。我还创建了一个模型并定义了表名以及可填写的列..:

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Category extends Model
{
use SoftDeletes;

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'categories';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'category'
];

/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
}

这是我的数据库播种器:

use Illuminate\Database\Seeder;
use App\Category;

class CategoryTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$category = new Category();
$category->category = 'ISF';
$category->save();
}
}

如果我在我的工具 Sequel Pro 中选择表格 categories,这就是我返回的内容:

CREATE TABLE `categories` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`category` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`deleted_at` timestamp NULL DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

我觉得一切都很好。但是,我在上面收到此错误。有什么想法吗?

亲切的问候

最佳答案

你可以使用下面的代码

public function run()
{
$row = array('category' => 'Purchasing',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now());
DB::table('categories')->insert($row);
}

代替 Eloquent

关于php - Laravel Eloquent 无法确定表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51265387/

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