【发布时间】:2015-11-06 09:52:54
【问题描述】:
我是 Laravel 的新手,
我正在尝试为一张桌子播种,而 artisan 总是返回代码 255。
这是我的代码
<?php
use App\Grade;
use Illuminate\Database\Seeder;
class GradeSeeder extends Seeder {
public function run()
{
//This doesn't even work
DB::table('Grade')->delete();
// Grade::create(['id' => '1','name' => "5 Kyu",'order' => 2]);
}
}
DatabaseSeeder.php
class DatabaseSeeder extends Seeder {
public function run()
{
Model::unguard();
//Seed the countries
$this->call('CountriesSeeder');
$this->command->info('Seeded the countries!');
$this->call('GradeSeeder');
$this->command->info('Seeded the grades!');
}
使用突击队
php artisan db:seed --class=GradeSeeder
or
php artisan db:seed // In this case seeding countries works but mine don't
这是模型:
class Grade extends Model {
protected $table = 'Grade';
public $timestamps = true;
protected $fillable = [
'name',
'order'
];
}
这里是迁移
class CreateGradeTable extends Migration {
public function up()
{
Schema::create('Grade', function(Blueprint $table) {
$table->increments('id');
$table->string("name")->unique();
$table->tinyInteger("order");
});
}
public function down()
{
Schema::drop('Grade');
}
}
- 有没有办法记录所发生的事情。仅使用来自 Artisan 的 255 代码修复错误并不是很好!
- 我的代码有什么问题?? 我只是评论了创建行以丢弃任何数据问题。 我的“等级”表存在但为空!
输入错误日志:composer install
> /usr/local/bin/composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
> php artisan clear-compiled
Warning: require(/Applications/XAMPP/xamppfiles/htdocs/kendo/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in / Applications/XAMPP/xamppfiles/htdocs/kendo/bootstrap/autoload.php on line 17
Fatal error: require(): Failed opening required '/Applications/XAMPP/xamppfiles/htdocs/kendo/bootstrap/../vendor/autoload.php' (include_path='.:') in / Applications/XAMPP/xamppfiles/htdocs/kendo/bootstrap/autoload.php on line 17
Script php artisan clear-compiled handling the post-install-cmd event returned with an error
[RuntimeException]
Error Output:
install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no- progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...
Process finished with exit code 255 at 19:51:06.
Execution time: 941 ms.
【问题讨论】:
-
Laravel 日志位于
storage/logs/laravel.log。想到的事情是您的Grade模型的某些列可能不是fillable。 -
另外,清空模型表的更简单方法是使用
Grade::truncate(),尽管您的方式也是正确的,所以这不是错误的原因(假设表名拼写正确Grade)。 -
Tx 供您参考,我没有可填写的内容。我添加了它,但它仍然不起作用:(另外,laravel.log 似乎只记录浏览器请求,我没有看到任何关于我的工匠错误的信息
-
您能否发布
database/seeds/DatabaseSeeder.php的内容以及您正在运行的确切播种命令? -
将 DatabaseSeeder、Model 和 Migration 添加到问题中