Closed cesarcruzc closed 7 years ago
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:
I am facing this issue. Any fixes yet?
I am also facing this issue. Any fix or solution aside from writing the SQL statement? Using Mysql 5.7, PHP 7.2, Laravel framework 6.18.38
Same issue still happening:
Works in my unit tests (sqlite), not on MySQL.
@themsaid This should probably be re-opened.
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".
Same here
For future adventurers: This error doesn't come from Laravel itself, but Doctrine DBAL. Upgrading it to a newer version (for me it's the latest to date - 3.x) may help.
"php": "^7.3|^8.0", "doctrine/dbal": "^3.3",
still not working when i want to change not nullable to nullable column. the only way to change the column properties is the way @cesarcruzc mentions:
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)"); } }); } }
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)
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:
php artisan make:migration create_empresa_table --create=table
alter_edit_logo_default_value_on_empresa_table --table=empresa