Ivan Petrov Ivan Petrov - 1 month ago 9
PHP Question

Getting error when create new table with laravel seeds

Very new in Laravel here and I'm sorry if the questions is stupid. I'm trying to create new table but getting this error


[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'vvas.buildings' doesn't exist


Here is my seed

class CreateBuildingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('buildings', function (Blueprint $table) {
$table->increments('id');
$table->string('street');
$table->string('neighborhood');
$table->text('description');
$table->timestamps();
});
}

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

Answer

When you want to CREATE table you use Schema::create. Schema::table is to MODIFY an existing table. So in your case would be

....
Schema::create('buildings', function (Blueprint $table) {
....

Here you can find more information about Database creation and migration

To create a new database table, use the create method on the Schema facade.

The table method on the Schema facade may be used to update existing tables.

Comments