I'm using Debian 9 with MariaDB 10.1.27, Composer 1.4.2 and Laravel 5.5.13.
I've created an empty database using CREATE DATABASE 'laravel', configured it in Laravel's .env config file and now I've sometimes the problem, that database actions hangs (nothing happens) or in the browser I get an timeout exceeded message. Connecting to the database using mysql -u laravel -p laravel is still possible - like SELECT's.
php artisan migrate
...is sometimes working like migrate:refresh and sometimes not. If it's not working, I always have to restart the MariaDB service and usually, it works then the first time again.
migrate:refresh for example clears the database and imports / loads most of the time 10 migrations and then, it's just doing nothing. I've already waited about 1 hour for this task, but it only keeps saying, that the migration table was missing and added and nothing more. Artisan doesn't even say, that it has imported / loaded 9 other tables...
For sending emails, I'm using supervisor, but it shouldn't be in use, while running migrate:refreshh;
Increasing the execution timeout doesn't help anything. So, what's the problem? In Homestead it's just working perfect. Are there any specific settings in MariaDB required? Or do I need to create the database with specific parameters like default charset?
Btw: If the application is running, I'm also sometimes getting the execution timeout error message, while browsing the web site.
When using Supervisor to control artisan queues, the deamon should definitely be stopped
sudo supervisorctl stop <YOUR_QUEUES>
while performing
artisan migrate:refresh
It will more often than not lead to a kind of race condition, while artisan is trying to lock the table jobs to delete it from the database and the Artisan queue is trying to lock the table jobs to perform its tasks.
The general query log (for this, I worked with MariaDB 10.1.27) shows something like this:
94 Prepare drop table if exists `jobs`
63 Query START TRANSACTION
67 Query SAVEPOINT trans2
67 Prepare select * from `jobs` where `queue` = ? and ((`reserved_at` is null and `available_at` <= ?) or (`reserved_at` <= ?)) order by `id` asc limit 1 for update
67 Execute select * from `jobs` where `queue` = 'user' and ((`reserved_at` is null and `available_at` <= 1511429487) or (`reserved_at` <= 1511429397)) order by `id` asc limit 1 for update
67 Close stmt
While the artisan:refresh command hangs, and jobs is being queued by Supervisor-powered job worker, the MariaDB server reports two connections (from the Laravel DB user in question) waiting for metadata lock.
At first I also went with restarting MariaDB, which solved the problem in a not so clean way. But then, stopping Supervisor, made the difference.
Related
I have two Laravel apps that use the same database. I moved migrations from app 1 to app 2.
Now I want to remove the pending migrations from app 2 due to that I moved the migrations files to it and tables exists in database.
Is any way to remove them from pending execution when php artisan migrate is executed?
Regards
You can add the migrations manually in the migrations table in the database, and that way they will be marked as executed.
Note that i assume both apps do not use the same database migrations table.
I have run a db:seed and in Laravel 5.4. Now I found that it was not to be run . So is there anyway in Laravel that we can undo the last db:seed and insert the table with previous data. Thanks in advance
The only way to undo your seed(s) is by deleting them manually. With this sql command that should go pretty fast. As long as no data has been added after the seed you don't want to lose.
DELETE FROM {$table} ORDER BY created_at DESC LIMIT {$number_data_seeds}
Database: Seeding is not migration, you can not rollback the last seed.
You can rollback all migrations and re-run all of your migrations and run seed, but you need to understand that when rolling back migrations, you lose all the data.
php artisan migrate: refresh --seed
Alternatively, you can look in the database/seeds folder and understand what changes you need to rollback and manually make changes to the database.
Please see the documentation https://laravel.com/docs/5.4/seeding
can you find that useful.
I created a MYSQL database using migrations, I added some data into it, but after that I recognized that I need to add a new column into my table.
I ran the command: 'php artisan migrate', but as it didn't work to synchronize
columns, it returns there is nothing to migrate.
So I ran the command 'php artisan migrate:reset', and then ran the command
'php artisan migrate' again, database schema updated correctly but for sure I
lost all my inserted data.
Now I'm just testing the application, but it would be very harmful if I found out that I should modify my database while it is runing with real data!!! What should I do in this case?
should I skip using migrations and create the Mysql database directly with
wamp? or use migration, but perform any later updates directly on database without updating the migration files? or there is another solution?
Answer
If you have already created a database table and realise you need to add more into it you can simply run: php artisan make:migration add_field_to_table_name --table=tableName
You then go into that file and create the new field. Once done simply run php artisan migrate and it'll add the new field into the desired table without causing any data loss.
Seeders
On another note, I would strongly suggest looking into seeders. This way when you're creating a project you can always refresh your migrations (wipe your database and re-migrate your tables) and then re-input the data using seeders.
you can create a migration to alter your tables. add new columns and more.
I am learning Laravel and I have encountered a problem when I want to refresh a migration.
php artisan migrate:refresh
I am using SQlite and below is the error I am getting
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 5 database is locked (SQL: drop table if ex
ists "generate_pins")
The problem seems like it comes from the SQlite having locked the database, How do I unlock the database? After I have unlocked, can I lock it again?
I am learning both Laravel and SQlite and any help will be appreciated. Thanks in advance.
In general, it looks like some process is using the database and it is locking the file or more likely you've made some kind of error in your code causing too many queries at the same time.
Please provide more detailed information. What OS, Laravel version, your database configuration (.env and config/database.php), your migration files and their contents, database structure (run slqite3 path/to/database.sqlite then .tables), and the contents of your migrations table (while still in sqlite run select * from migrations;).
In my case:
Delete database.sqlite
php artisan optimize:clear
php artisan migrate
I have a problem with Laravel (5.1.x) and Migrations. I am running it on an windows server with an integrated service account - so dont the application pool runs as the same account as the database.
Do get the correct scheme of my database, ill changed in the database.php file the name for the migrations table to:
'migrations' => 'dbo.migrations',
Because otherwise it will use my Scheme (because the command line runs as my account)
But when ill use that and run
php artisan migrate
It works only the first time, when i run it again, i tells me that there is already a migrations table in my database.
When ill use with:
'migrations' => 'migrations',
And the schema is now username.migrations it works when ill run the commands with my user.
It looks like that laravel is checking anywhere else if the migrations table exists, and try to create it again.
How can ill use the global database scheme with migrations (ill use that for every other tables too, and here it works fine as expected)
Any Ideas? Thanks in advance.