0

I'm new to Laravel,

I'm trying to seed a table, and artisan always returns code 255.

Here is my code

<?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!');
    }

Commando used

php artisan db:seed --class=GradeSeeder
or
php artisan db:seed // In this case seeding countries works but mine don't

Here is the model:

class Grade extends Model {

    protected $table = 'Grade';
    public $timestamps = true;

    protected $fillable = [
        'name',
        'order'
    ];

}    

and here is the migration

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');
}
}  
  1. Is there a way to have a log of what happens. Fixing bug with just a 255 code from Artisan is not so great!
  2. What's wrong with my code?? I just commented the creation lines to discard any data problems. My table "Grade" exists and is empty!

Error Log when typing: 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.
Juliatzin
  • 18,455
  • 40
  • 166
  • 325
  • 1
    The Laravel log is located in `storage/logs/laravel.log`. The thing that comes to mind is that some of the columns of your're `Grade` model might not be [fillable](http://laravel.com/docs/5.1/eloquent#mass-assignment). – Bogdan Nov 05 '15 at 16:37
  • Also the easier way to empty a model's table is with `Grade::truncate()`, although your way is correct as well, so it's not the cause of the error (assuming the table name is correctly spelled `Grade`). – Bogdan Nov 05 '15 at 16:43
  • Tx for your obsversation, I didn't have fillables. I added it, but it still doesn't work :( Also, laravel.log seems to log only browser request, I don't see anything about my artisan error – Juliatzin Nov 05 '15 at 17:40
  • Can you please post the contents of `database/seeds/DatabaseSeeder.php` and the exact seeding command you're running? – Bogdan Nov 05 '15 at 17:45
  • added DatabaseSeeder, Model and Migration to question – Juliatzin Nov 05 '15 at 18:52

1 Answers1

1

There are two obvious inconsistencies there:

  1. Every column added with the model's create method must be fillable, yet the id is not. Also you should not pass it at all (unless you really need to for some reason) because it's defined as the primary key in the migration, thus auto incrementing so it populates itself. So this should suffice Grade::create('name' => '5 Kyu', 'order' => 2]);
  2. The migration is not defining any timestamp columns yet your model has protected $timestamps = true;. So either add $table->timestamps() to your migration or set $timestamps to false in your model.

I've installed a clean Laravel copy and ran the migration you posted, created the model and the seeding class, and after fixing the issues listed above, running php artisan db:seed --class=GradeSeeder was done without any errors.

Bogdan
  • 43,166
  • 12
  • 128
  • 129
  • mmm. you are right. I've added timestamp, refresh the db, add the id to fillable...and run it again it still doesn't work for me :( – Juliatzin Nov 05 '15 at 20:31
  • You say that the `php artisan db:seed --class=GradeSeeder` command returns the code 255, but from my experience artisan usually returns a more detailed error when failing. Could you please post the exact output of the command? – Bogdan Nov 05 '15 at 20:49
  • nop, no more: > php artisan db:seed --class=GradeSeeder Process finished with exit code 255 at 15:49:22. Execution time: 2,320 ms. – Juliatzin Nov 05 '15 at 21:49
  • Is debug mode enabled on your Laravel app? Also could you please specify your OS and PHP version. – Bogdan Nov 05 '15 at 22:25
  • Debug is On, Mac OS Yosemite, PHP Version 5.6.12, local environement. – Juliatzin Nov 05 '15 at 22:47
  • Does it run correctly if you create a simple route with a closure like [this](http://hastebin.com/uhebadobuz.php)? – Bogdan Nov 05 '15 at 23:08
  • I should put it in routes.php? – Juliatzin Nov 05 '15 at 23:49
  • Yes, and access `http://localhost/seed` (or whatever hostname you have setup locally). – Bogdan Nov 05 '15 at 23:59
  • it works this way, but when I run the same content from artisan, it fails... problem should me my artisan file??? – Juliatzin Nov 06 '15 at 01:23
  • Possibly. Try running `php artisan clear-compiled` then `php artisan optimize` and see if it works. If that doesn't fix it, you could delete the `vendor` directory and run `composer install` again so it fetches all the packages again. – Bogdan Nov 06 '15 at 01:27
  • aaaaa, composer install is failing: posting log in question – Juliatzin Nov 06 '15 at 01:52
  • I did composer install in another computer, and it was ok. But when in this same computer, I run php artisan db:seed --class=GradeSeeder , it says: [ReflectionException] Class GradeSeeder does not exist – Juliatzin Nov 06 '15 at 02:24
  • I fixed my composer and now, it's seeding well! Tx – Juliatzin Nov 06 '15 at 16:08