我是新來的Laravel,播種表中laravel未能5.1
我試圖播種表,工匠總是返回代碼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個代碼修復bug並不是那麼好!
- 我的代碼有什麼問題? 我剛剛評論了創建線以放棄任何數據問題。 我的表「年級」存在並且是空的!打字時
錯誤日誌:作曲家安裝
> /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'模型中的某些列可能不是[可填寫](http://laravel.com/docs/5.1/eloquent#mass-assignment)。 – Bogdan
也可以通過'Grade :: truncate()'來清空模型表的簡單方法,儘管你的方法也是正確的,所以它不是錯誤的原因(假設表名正確拼寫'Grade')。 – Bogdan
Tx爲您的obsversation,我沒有可操作的文件。我添加了它,但它仍然不起作用:( 另外,laravel.log似乎只記錄瀏覽器請求,我沒有看到任何關於我的工匠錯誤 –