Support the ongoing development of Laravel.io →
posted 8 years ago
Database

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]
Last updated 2 years ago.
0

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.