DEV Community

Dimitrios Desyllas
Dimitrios Desyllas

Posted on

Can you help me identify why I cannot run migrations in testing?

Hello can you help me with the following question I did:

https://laracasts.com/discuss/channels/testing/why-by-running-migraterefresh-on-test-setup-phase-fails-to-run-the-mugration-scripts

I try to run migrations for a pre-existing schema on laravel 5.7 application. But as the question says the migrations fail.

Top comments (4)

Collapse
 
hakobyansen profile image
Senik Hakobyan

Try to specify your pre-existing schema in the phpunit.xml config file.

<php>
         ...
        <env name="DB_DATABASE" value="your-schema-name" />
</php>

Make sure you have backup of that db before running the test. Laravel's DatabaseMigrations trait will drop everything and re-migrate.

Collapse
 
pcmagas profile image
Dimitrios Desyllas

I have tried that and I still get the error.

Collapse
 
hakobyansen profile image
Senik Hakobyan

Are you able to run that migration outside of the test?

Thread Thread
 
pcmagas profile image
Dimitrios Desyllas • Edited

By setting the test database, nope I am unable to run the migrations.

The cause is that the postgresql database I am using actually keeps the columns into the table even if I delete it from the table and just hides it from the user.

The solution is to reconstruct the test database. So how I can prepend my existing migrations with one that generates the database?