The order of the migrations obviously matters. Is that "manual" migration the first one that runs (which would be the first migration listed in the migrations dir)?
migrate:fresh fails while fresh migrate works
When I execute php artisan migrate all the migrations are performed as expected. When I run php artisan migrate:fresh tables are dropped but when it internally calls migrate it fails telling me that a table is not found.
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mysql.users' doesn't exist
FYI: deleting tables manually and migrate works; rolling back and migrate works as well
The thing is I am not using a normal migration for the users table since the project didn't have any when I overtook. Thus, I am using a mysql dump file which I migrate using exec like this:
public function up()
{
$script = __DIR__ . '/old_tables.bz2';
$config = \DB::getConfig();
$username = $config['username'];
$password = $config['password'];
$host = $config['host'];
$database = $config['database'];
$command = "bunzip2 < $script | " .
"mysql -h$host -u$username -p$password $database 2>/dev/null | " .
"grep -v \"Warning: Using a password\" || :";
exec($command, $output, $ret_var);
if ($ret_var !== 0) {
throw new ErrorException("Message: " . implode(';', $output));
}
}
It seems that it wants to execute the 3rd migration I have (wants to add a column to users table and a foreign key) is run during the time the first migration is run.
But I looked it up already and exec should run synchronously. I also experimented with a sleep.
Weird for me is that it works if I run migrate myself but it doesn't when run after dropping the tables in migrate:fresh.
I appreciate your help.
info: I know it would be more clean if I used normal migrations and seeds instead but this would take a huge amount of time right now and I don't have it, that's why I will stick to this method for now.
Edit:
I figured out what causes the problem which are the views. It seems migrate:fresh only removes all the tables and then the migrate fails when the views are still in the database. I don't know how to solve it though. Is there some kind of callback or event I can register to to add some kind of cleanup to remove my views before everything is added again?
Please or to participate in this conversation.