Php 拉威尔雄辩不定表
我已经创建了一个数据库种子播撒器来为我的表进行种子播撒,这是我几秒钟前通过迁移创建的。但是,我在运行播种机时遇到以下错误:Php 拉威尔雄辩不定表,php,mysql,laravel,eloquent,laravel-seeding,Php,Mysql,Laravel,Eloquent,Laravel Seeding,我已经创建了一个数据库种子播撒器来为我的表进行种子播撒,这是我几秒钟前通过迁移创建的。但是,我在运行播种机时遇到以下错误: 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
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);
}
尽管雄辩似乎您遇到了错误,因为您在模型中将$table保持为“受保护”。将其更改为“公共” 像这样:
public $table = "categories";
protected $primaryKey = "id";
如果添加了正确的数据库、用户名和密码,请检查.env文件。您应该检查.env文件中的数据库连接,或者您可以在您的模型中尝试以下操作:
protected $connection = 'trier_taxibus';
您是否指定了正确的数据库?除了使用不同的数据库外,此处未发现任何其他问题。
trier\u taxibus
是正确的数据库吗?添加一些新文件后,最好发出composer du
来重新填充自动加载列表。