Reputation: 413
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");
}
}
<?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
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
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
Reputation: 81187
Use either --table="tableName"
(Schema::table) for updating your table or --create="tableName"
(Schema::create) for creating a new one.
Upvotes: 2