C
C
Camaro672017-11-08 13:51:06
Database migration
Camaro67, 2017-11-08 13:51:06

How to name migrations to avoid class name conflict?

Hello! How to properly name migrations to avoid migration class name conflicts?
I will give an example, though fictional, but the essence is fully reflected. Let's say we created a migration named create_examples_table (class name CreateExamplesTable ), which in turn will create a table in the database. After some time, we decided to delete this table and created the appropriate migration for this. And after some more time, they decided that this table is still needed and again created a migration under the name create_examples_table (class name CreateExamplesTable ). As a result, we have a conflict in the naming of classes, and when executing, for example, the php artisan migrate:reset command, we will get an error.
Of course, you can add a date to the migration name, but this is, in my opinion, a so-so solution.
UPD: adding the date to the name of the migration meant adding the date not manually, but to make a wrapper over the standard make:migration command .
Thanks in advance for good advice.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2018-10-08
@dlnsk

The problem is sucked from the finger.
Well, you had a conflict - added "2" to the class, performed dump-autoload and that's it! It seems that you delete and restore tables every other day.

M
myxasa, 2017-11-08
@myxasa

the first migration creates a table,
then in a month you are supposed to delete the table - do a migration where on UP you have a sql query in the DROP TABLE style, but on the down () method you must CREATE THIS TABLE as it was before
, in this case everything will be ok

A
ajaxtelamonid, 2017-11-16
@ajaxtelamonid

Well, there is an old rule - to call migrations as verbose as possible so that this does not happen. create_table_for_examples_again for example. You are not limited by anything in the names of migrations, by any compatibility rules or code style conventions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question