framework: Migrations error There is no column with name '{column_name}' on table '{table_name}'.

  • Laravel Version: 5.4.*
  • PHP Version: 7.1.1
  • Database Driver & Version: pgsql - 9.6.2

Description:

I have created a alter table migration for change the string length of a column and default value but when I run php artisan:migrate I got this error:

[Doctrine\DBAL\Schema\SchemaException] There is no column with name 'logo' on table 'empresa'.

Steps To Reproduce:

  1. Schema empresa table:

php artisan make:migration create_empresa_table --create=table

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateEmpresaTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('empresa', function (Blueprint $table) {
            $table->increments('id');

            $table->string('nombre_comercial', 200);
            $table->string('nombre_legal', 200);
            $table->string('nit', 20);
            $table->string('telefono', 10);
            $table->string('direccion', 200);
            $table->string('correo', 100);

            $table->integer('tipo_sociedad_id')->unsigned();

            $table->integer('tipo_regimen_id')->unsigned();

            $table->string('codigo_ciuu', 40);

            $table->integer('tipo_contribuyente_id')->unsigned();

            $table->enum('responsable_iva', ['Si', 'No']);
            $table->enum('retencion_fuente', ['Si', 'No']);
            $table->enum('gran_contribuyente', ['Si', 'No']);
            $table->enum('auto_retenedor', ['Si', 'No']);
            $table->smallInteger('numero_empleados');
            $table->string('logo', 20);

            $table->integer('user_id')->unsigned();

            $table->timestamps();
            $table->softDeletes();
        });
    }

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

  1. Schema to alter table field

alter_edit_logo_default_value_on_empresa_table --table=empresa

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AlterEditLogoDefaultValueOnEmpresaTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('empresa', function (Blueprint $table) {
            $table->string('logo', 100)->default('public/empresa/logo/default.png')->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('empresa', function (Blueprint $table) {
            $table->string('logo', 20)->change();
        });
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 24 (6 by maintainers)

Most upvoted comments

Hi, facing the same issue, any hint?

Also ran into this issue. This is definitely still happening!

I have the exact same problem. I installed doctrine/dbal, I’m changing a string column length. When I use change() it says “no column with name” and when I leave out the change() call, it tries to add my column and says “Duplicate column name”. Any help would be appreciated!

@themsaid This should probably be re-opened.

Issue still exists. Creating a new column, carrying all the data from old column to the new one looks like the only solution rn. Does anyone have a better idea? (except @cesarcruzc’s solution)

The issue still exists.

I am trying to change a default value of a column, but I got the same error “Column does not exists”.

If I don’t put the change method at the end, I got a “Duplicate column error”.