Error during upgrade - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name ‘smtp_host’ (Connection: mysql, SQL: alter table companies add smtp_host varchar(191) null)

Hi,
I followed instruction at the page How to Update InvoiceNinja v.5 on VM/bare metal

at the step sudo -u www-data php artisan migrate I receive the following error:

┌ Are you sure you want to run this command? ──────────────────┐
│ Yes │
└──────────────────────────────────────────────────────────────┘

INFO Running migrations.

2024_02_16_011055_smtp_configuration … 1s FAIL

Illuminate\Database\QueryException

SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name ‘smtp_host’ (Connection: mysql, SQL: alter table companies add smtp_host varchar(191) null)

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:825
821▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
822▕ );
823▕ }
824▕
➜ 825▕ throw new QueryException(
826▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
827▕ );
828▕ }
829▕ }

  +9 vendor frames

10 database/migrations/2024_02_16_011055_smtp_configuration.php:15
Illuminate\Support\Facades\Facade::__callStatic()
+25 vendor frames

36 artisan:35
Illuminate\Foundation\Console\Kernel::handle()

Login in the app is okay, app version is update to 5.10.26, the last version, but if I run php artisan migrate:status the operation of migration is not finished successfully

2024_01_12_073629_laos_currency_translation … [19] Ran
2024_01_29_080555_2024_01_29_update_timezones_naming … [19] Ran
2024_02_06_204031_correction_for_krw_currency … [20] Ran
2024_02_16_011055_smtp_configuration … Pending
2024_02_28_180250_add_steps_to_subscriptions … Pending
2024_03_07_195116_add_tax_data_to_quotes … Pending
2024_03_14_201844_adjust_discount_column_max_resolution … Pending
2024_03_24_200109_new_currencies_03_24 … Pending
2024_04_24_064301_optional_display_required_fields_payment_gateways … Pending
2024_05_02_030103_2024_05_02_update_timezones … Pending
2024_05_03_145535_btcpay_gateway … Pending
2024_05_19_215103_2024_05_20_einvoice_columns … Pending
2024_05_26_210407_2024_05_28_kwd_precision … Pending
2024_06_02_083543_2024_06_01_add_einvoice_to_client_table … Pending
2024_06_04_123926_2024_06_04_fixes_for_btc_migration … Pending
2024_06_08_043343_2024_06_08__i_s_k_currency_precision … Pending
2024_06_11_231143_add_rotessa_gateway … Pending
2024_06_19_015127_2024_06_19_referral_meta_data … Pending
2024_06_23_040253_2024-06-23_indexesforinvoiceid_payment_hashes … Pending
2024_07_10_043241_2024_07_10_invoice_id_index_on_projects_table … Pending
2024_07_16_231556_2024_07_17_add_dubai_timezone … Pending
2024_07_29_235430_2024_30_07_tax_model_migration … Pending
2024_08_02_144614_alter_companies_quickbooks … Pending
2024_08_04_225558_tax_model_migration_v2 … Pending
2024_08_21_001832_add_einvoice_option_license … Pending

Any hint?
Thanks

Hi,

It looks like a past migration failed part way through. You can fix it by manually commenting out the parts that have already run and then running ‘php artisan migrate’.

Hi,
how do I know what was correctly migrated and if everything is okay? Also if I re-run it, it will stop at the same point,

2024_02_16_011055_smtp_configuration … Pending

You’ll need to comment out that part that’s failing for the migration to complete.

I moved out of the directory the file 2024_02_16_011055_smtp_configuration.php and run again the command php artisan migrate . Everything is fine but if I run php artisan migrate:status, the 2024_02_16_011055_smtp_configuration is still in pending status.

Is there a way to flag it as done?

You don’t want to move the file, you need to comment out the parts of the file that which have already run.

In the database I see all the column (mentioned in the file 2024_02_16_011055_smtp_configuration) already present. Last column you see in the pic is “nullable”

Do I just comment out all the content of the file or only a part of it?

You need to comment out the parts of tue file that have already been run

Okay, I commented out all the parts then

Please see my first comment

a possible solution… i have a similar problem

Thanks but in my case the columns were already present, so I commented out the php script, run again the migration and the value was correctly added to the database (there is a table called migrations).

1 Like