Reputation: 151
I was trying to create a migration in laravel using the code here. But unfortunately it pops out an error like given here. I saw some answers that i create the table manually.. but that would be so much against the whole idea of migrations.. no?
The migration file 2018_05_05_203731_create_cities_table is here:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCitiesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('cities', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->text('Name');
$table->json('info');
$table->integer('country_id');
$table->float('lat');
$table->float('lon');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('cities', function (Blueprint $table) {
//
});
}
}
The error that was churned out is here:
C:\Users\think\Documents\NZ\blog>php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[08006] [7] FATAL: database "tripplan1" does not exist (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations) es not exist") at C:\Users\think\Documents\NZ\blog\vendor\laravel\framework\src\Illuminate\Databasee\Connection.php:458\Connection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error
e\Connection.php:458 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) {664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| }
C:\Users\think\Documents\NZ\blog>php artisan migrate Migration table created successfully.
Illuminate\Database\QueryException : SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "cities" does not exist (SQL: alter table "cities" add column "id" serial primary key not null, add column "created_at" timestamp(0) without time zone null, add column "updated_at" timestamp(0) without time zone null, add column "Name" text not null, add column "info" json not null, add column "country_id" integer not null, add column "lat" double precision not null, add column "lon" double precision not null) at C:\Users\think\Documents\NZ\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) {
664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668|
Exception trace:
1 PDOException::("SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "cities" does not exist") C:\Users\think\Documents\NZ\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458 2 PDOStatement::execute() C:\Users\think\Documents\NZ\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
Please use the argument -v to see more details.
Any help will be highly appreciated.
Edit: The whole error was wrongly entered. The database name was corrected...
Upvotes: 2
Views: 3252