Monday, May 7, 2018

IlluminateDatabaseQueryException SQLSTATE[42P01]: Undefined table: 7 ERROR: during migration - development

IlluminateDatabaseQueryException SQLSTATE[42P01]: Undefined table: 7 ERROR: during migration

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 IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

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:UsersthinkDocumentsNZblog>php artisan migrate

IlluminateDatabaseQueryException : 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:UsersthinkDocumentsNZblogvendorlaravelframeworksrcIlluminateDatabaseeConnection.php:458Connection.php:664
660| // If an exception occurs when attempting to run a query,
we’ll format the error
eConnection.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:UsersthinkDocumentsNZblog>php artisan migrate Migration table
created successfully.

IlluminateDatabaseQueryException : 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:UsersthinkDocumentsNZblogvendorlaravelframeworksrcIlluminateDatabaseConnection.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:UsersthinkDocumentsNZblogvendorlaravelframeworksrcIlluminateDatabaseConnection.php:458
2 PDOStatement::execute()
C:UsersthinkDocumentsNZblogvendorlaravelframeworksrcIlluminateDatabaseConnection.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…



from Laravel Questions and Answers https://laravelquestions.com/laravel/illuminatedatabasequeryexception-sqlstate42p01-undefined-table-7-error-during-migration/
via Lzo Media

No comments:

Post a Comment