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'.
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');
}
}
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();
});
}
}
I have to do this for the moment:
alter_edit_logo_default_value_on_empresa_table.php
<?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)->defaults('public/empresa/logo/default.png')->change();
if (env('DB_CONNECTION') === 'mysql'){
// Mysql
DB::statement("ALTER TABLE empresa CHANGE COLUMN logo logo varchar(100) NOT NULL DEFAULT 'public/empresa/logo/default.png'");
} else if (env('DB_CONNECTION') === 'pgsql'){
// PostgreSQL
DB::statement("ALTER TABLE empresa ALTER COLUMN logo TYPE varchar(100), ALTER COLUMN logo SET DEFAULT 'public/empresa/logo/default.png'");
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('empresa', function (Blueprint $table) {
// $table->string('logo', 20)->change();
if (env('DB_CONNECTION') === 'mysql'){
// Mysql
DB::statement("ALTER TABLE empresa CHANGE COLUMN logo logo varchar(20)");
} else if (env('DB_CONNECTION') === 'pgsql'){
// PostgreSQL
DB::statement("ALTER TABLE empresa ALTER COLUMN logo TYPE varchar(20)");
}
});
}
}
If you're adding a new column, don't call the method change()
@deleugpn I am changing the length and the defaults value for the column logo on table empresa.
Did you install doctrine?
yes, I have installed doctrine/dbal
composer require doctrine/dbal
Try adding the create
& table
callbacks in the same file. I think this should work.
Closing for lack of activity.
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!
Same issue here, @themsaid why would this be closed if no one solved this issue?
Also ran into this issue. This is definitely still happening!
Hi, facing the same issue, any hint?
i got this on new version of pgsql (on older it works normally)
exception is wrong - this column exists
Yes, this issue exists
Me too with sqlite
I am experiencing this issue with https://github.com/optimistdigital/nova-notes-field migration when ran on our staging environment.
PHP 7.4.5
Laravel Framework 7.15.0
Laravel Nova 3.6.0
MySQL 5.7.26
I have also checked permissions as depicted in https://github.com/doctrine/dbal/issues/1990
Note: when ran locally with the same setup there were not any issues.
difference is the operating system:
Most helpful comment
Hi, facing the same issue, any hint?