iOi
iOi

Reputation: 413

laravel migration creates different schema

I was watching a tutorial from Laracast titles "Laracast Digging In" and the first part illustrates how to use eloquent simply by doing.

# app/models/tasks.php
class tasks extends Eloquent{

}

then goes on to do
php artisan migration:make create_tasks_table --create --table="tasks"

Then a migration file is made that looks like this.

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTasksTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create("tasks", function(Blueprint $table)
        {
            $table->increments("id"); 
                        $table->timestamps(); 
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop("tasks");
    }

}

While I do exactly the same, I am getting slightly a different result.

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTasksTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('tasks', function(Blueprint $table)
        {
            //
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('tasks', function(Blueprint $table)
        {
            //
        });
    }

}

As you can see, aside my approach omitting

$table->increments("id"); 
$table->timestamps(); 

It has entirely replaced create with table here.

Schema::table('tasks', function(Blueprint $table)
        ^^ is 'create' in the tutorial. 

Why, is this happening. If I simply ignore this and start following the tutorial I can't get anything to work. And I don't want to modify this by hand, so why is this happening and how do I solve it.

Upvotes: 0

Views: 1390

Answers (3)

Paul Bele
Paul Bele

Reputation: 1534

You are using the command wrong

Based on Laravel tutorial use this :

For creating a table

php artisan migrate:make create_tasks_table --create=tasks

For updating a table

php artisan migrate:make create_tasks_table --table=tasks

Basically you need to use --create OR --table not both. when you are using --create , then the migration will be with Schema::create indicating that the migration will create a table

when you are using --table , then the migration will be Schema::table indicating that a table will be updated

Upvotes: 3

Arthur BALAGNE
Arthur BALAGNE

Reputation: 313

I'm pretty sure in the tutorial you followed, the developper used JeffreyWay/Laravel-4-Generators. utill you feel confortable with Laravel4, ignore the generator and replace 'table' by create or drop according to the action you want to execute.

Sorry for my bad english

Upvotes: 2

Jarek Tkaczyk
Jarek Tkaczyk

Reputation: 81187

Use either --table="tableName" (Schema::table) for updating your table or --create="tableName" (Schema::create) for creating a new one.

Upvotes: 2

Related Questions