Reputation: 2235
I am converting a 12 year old frameworkless php app into a Laravel app. The old app had two separate user tables which I have merged. Merging them requires massaging the data. I created a migration to massage the data in one of my tables.
My up() function looks like this:
public function up()
{
$users = User::all();
foreach($users as $user) {
if ($user->staff_id = '0') {
$user->role = '4';
} elseif ($user->role != '1') {
$user->role = '3';
}
$user->save();
}
}
I had run a similar function in a migration moments previously which ran fine. However this one produced the following output:
myusername at local in ~/Sites/tgdp/trunk
> mamp-php artisan migrate
myusername at local in ~/Sites/tgdp/trunk
>
And when I looked in my migrations table and at the User table, it was obvious the migration had not been run.
So, to recap. No error thrown. No "Nothing to Migrate." No success response. No effect on the database. * Edit: No errors listed in the logs.
Any idea why this might have happened?
Upvotes: 0
Views: 744
Reputation: 2235
So, it turns out that the problem was that looping through and saving all of those users was very memory intensive. The solution was to give php limitless access to memory. Like so:
php -d memory_limit=-1 artisan migrate
Once I did that the code ran fine.
Upvotes: 1