我正在创建具有角色的用户登录管理系统.当我运行命令`$php-artisan-db:seed`时,我得到了如下错误



我正在创建具有角色的用户登录管理系统。当我运行命令$ php artisan db:seed时,我收到如下错误

错误异常

file_get_contents(C:\examplep\htdocs\bizzcomputer\database/dumps/your_database.sql(:无法打开流:没有这样的文件或目录

at C:xampphtdocsbizzcomputerdatabaseseedsDatabaseSeeder.php:26
22|             // Remove foreign keys for now
23|             DB::statement('SET FOREIGN_KEY_CHECKS = 0');
24| 
25|             // Now we seed using our database dump of
> 26|             DB::unprepared(file_get_contents($sql));
27| 
28|             // Enable foreign keys
29|             DB::statement('SET FOREIGN_KEY_CHECKS = 1');
30| 

1 C:\examplep\htdocs\bizzcomputer\database\seeds\DatabaseSeeder.php:26file_get_contents("C:\examplep\htdocs\bizzcomputer\database/dumps/your_database.sql"(

<blockquote\>2 C:\examplep\htdocs\bizzcomputer\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:37数据库种子程序::run((

数据库种子程序

<?php
use IlluminateDatabaseSeeder;
use IlluminateSupportFacadesDB;
use IlluminateSupportFacadesHash;
use IlluminateSupportStr;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// Get the databse dump we wish to use
$sql = base_path('database/dumps/your_database.sql');
if ($sql) {
// Remove foreign keys for now
DB::statement('SET FOREIGN_KEY_CHECKS = 0');
// Now we seed using our database dump of
DB::unprepared(file_get_contents($sql));
// Enable foreign keys
DB::statement('SET FOREIGN_KEY_CHECKS = 1');

$this->call(RolesTableSeeder::class);
$this->call(UsersTableSeeder::class);
}
}
}

用户TableSeeder

<?php
use AppUser;
use AppRole;
use IlluminateDatabaseSeeder;
use IlluminateSupportFacadesDB;
use IlluminateSupportFacadesHash;
use IlluminateSupportStr;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
User::truncatte();
DB::table('role_user')->truncate();
$adminRole = Role::where('name', 'admin')->first();
$authorRole = Role::where('name', 'author')->first();
$userRole = Role::where('name', 'user')->first();
$admin = User::create([
'name' => 'Admin User',
'email' => 'admin@admin.com',
'password' => Hash::make('password')
]);
$author = User::create([
'name' => 'Author User',
'email' => 'author@author.com',
'password' => Hash::make('password')
]);
$user= User::create([
'name' => 'Generic User',
'email' => 'user@user.com',
'password' => Hash::make('password')
]);
$admin->roles()->attach($adminRole);
$author->roles()->attach($authorRole);
$user->roles()->attach($userRole);
}
}

错误消息几乎说明了所有

ErrorException

file_get_contents(C:\examplep\htdocs\bizzcomputer\database/dumps/your_database.sql(:无法打开流:没有这样的文件或目录。

它正在存储库的database/dumps目录中查找一个名为your_database.sql的文件。

请检查此文件是否存在,以及是否为其分配了正确的权限

//Remove foreign keys for now
DB::statement('SET FOREIGN_KEY_CHECKS = 0');
$this->call(RolesTableSeeder::class);
$this->call(UsersTableSeeder::class);
// Enable foreign keys
DB::statement('SET FOREIGN_KEY_CHECKS = 1');

相关内容

最新更新