Hi, I'm newbie in Laravel framework. I'm facing errors when I try to migrate some database table. Below is my error detail return from artisan.
[code]
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'todosapp.todos'
doesn't exist (SQL: alter table todos
add id
int unsigned not null auto
_increment primary key, add title
varchar(255) not null, add done
tinyi
nt(1) not null, add created_at
timestamp null, add updated_at
timestamp
null)
[PDOException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'todosapp.todos' doesn't exist
[/code]
[code]
<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateTodoTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('todos', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->boolean('done'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('todos'); } } [/code]You can check if a table exists with
if (Schema::hasTable('todos'))
{
//
}
When creating a table, don't use Schema::table but do the following:
Schema::create('todos', function($table)
{
$table->increments('id');
});
Also use the artisan command to create migrations
php artisan make:migration create_todo_table --create=todos
use the --table option if you want to create a migration to alter a table
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community