Laravel php artisan migrate not working - php

When I try to use 'php artisan migrate' in Laravel I get 2 errors:
[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 26 file is encrypted or is not a database (SQL: select * from sqlite_master where type = 'table' and name = migrations)
[PDOException] SQLSTATE[HY000]: General error: 26 file is encrypted or is not a database
I created a storage/database.sqlite file before attempting the migration. I also edited the config/database.php, making the default=sqlite. I am using windows and have sqlite3 installed.
Has anyone encountered this/know how to get past it?

I had the same results, in my case the /database/database.sqlite file was not empty.
I deleted the contents reran
php artisan migrate and the migration table was created successfully.

Running Laravel in Windows under the Powershell console I was getting the same errors as the original poster. The documentation reads After creating a new SQLite database using a command such as touch database/database.sqlite... The Powershell equivalent of touch is typically Out-File FILENAME
PS D:\Learning\PHP-Laravel\database> out-file database.sqlite
PS D:\Learning\PHP-Laravel> php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 26 file is not a database...
When creating my database.sqlite file I received these errors. I deleted the database and recreated it using the New-Item command and it worked properly
new-item -ItemType File -Name database.sqlite
PS D:\Learning\PHP-Laravel> php artisan migrate
Migration table created successfully.

Check the file you made as .sqlite and make sure it is empty if not then make it empty
database/db.sqlite
then run migration

If somebody came here with the same error with manually created table in sqlite db - it could be the sqlite version mismatch. I solved the same error by emptying db file and recreate the table with getConnection()->statement('CREATE TABLE

check if your .sqlite file is empty and the is no indentation(no spaces)

Related

Got an error while Laravel Project Transfer in another folder

I copy my Laravel project from one folder to another folder. I tried to run php artisan migrate, but I got an error. No any command can be executed successfully in the new root folder. I tried to run composer update & composer install but it also does not work.
The error is:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db_name.table_name' doesn't exist (SQL: select column from table_name )
I changed the database name from .env. The problem is solved if the database is imported from the old database.

PHP artisan returns access denied for database connection in Laravel

I transferred a Laravel project based on moving Laravel project between computers
Everything was fine at the first look. I could install the composer without any problems, then I set my environmental variables in my .env such as database name, database user and so on.
When I started using the following command,
php artisan cache: clear
I got these two errors,
In Connection.php line 664:
SQLSTATE[HY000] [1045] Acess denied for user 'root'#'localhost' (using password: Yes) (SQL: select * from information_schema.tables where tabale_schema = *** and table_name = ****)
In Connector.php line 67:
SQLSTATE [HY000] [1045] Access denied for user 'root'#'localhost' (using password: Yes)
Further Information:
It seems .env has not been read by the application because when I browse the homepage of the app, I got Whoops error which shows environmental variable is empty.
I tested my database connection such as its username, password, and other parameters, I know they are working properly.
In the end, I attached a photo in order to elaborate on the issue.
Interestingly, in my .env file, DB_DATABASE value is "nlp" and DB_USERNAME equals "Javad" but as you can see in the errors, they are not working, and the Artisan assumes the root as the user!
After you move a Laravel project to another location, The first thing you have to do is regenerate APP_KEY in the .env file by running the command from your application root directory:
php artisan key:generate
After that, you reconfigure your cache:
php artisan config:cache
Additionally, make sure all your database parameters in your .env file and config/database.php are correct and the same as your previous Laravel setup - You can change them manually and then reconfigure your cache as shown above. If not (for instance, the database name is changed), you may have to rerun your database migrations and seeders again:
php artisan migrate
and
php artisan db:seed
I think the configuration files are not writable by the apache user, considering you are using apache. Make sure you have given write permission to bootstrap/cache for the user. This directory contains the cached configuration files.If that is the case the congratulations will be loaded from here and your previously used configuration will be loaded which may be causing the issue.
Also you need to give write permission to the storage directory too. As there is the log file and apache user needs to write on that too.
Step 1: Go to the project path project_name\bootstrap\cache folder and remove the marked file config.php from the mentioned folder.
Step 2: Run the following command
composer dump-autoload
php artisan clear-compiled
php artisan config:clear
php artisan cache:clear
php artisan config:cache
I hope that it will work now!
Open the .env file and edit it. Just set up correct DB credentials:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Your Database Username, If no username has been set then by default there is a root as a username
DB_PASSWORD= // Your Database Password, If no password is set on the database, clear it
After completion of .env edit please enter this command in your terminal for clear cache:
php artisan config:cache
If there is still the same error then try another possible solution.
I had also face the same problem, I tried all the possible answers in StackOverflow but nothing could help me, this solution worked on the first try:
If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after changing your .env file values.
I found this solution from here laravel.io (Read the solution of Byjml)

Error: SQLSTATE[HY000] [1049] Unknown database 'old_db' when in '.env' a new db is defined

After the database has moved to a different server and a different schema name, I updated the .env file and when entering php artisan config:cache it writes the error message
"SQLSTATE[HY000] [1049] Unknown database 'OLD_DB'" - (OLD_DB refers to
the database name before the change).
I don't know why it still looks for the old name as if I didn't update the .env file. I also tried to write php artisan cache:clear and even just php artisan alone and received this error. Also composer update did not help - in the end it tries to run #php artisan package:discover.
Eventually I managed to solve the problem by clearing the cache:
rm -f bootstrap/cache/*
This allowed me to (finally) run:
php artisan config:clear
and the new configuration was on the air.

ErrorException + unlink + Resource temporarily unavailable + Laravel 5.5

I'm a newbie in Laravel World. I've downloaded a project from gitlab.com and tried several time to run that project in my laptop.
In that project I've 6 migration files:
users_table
password_resets
posts_table
comments_table
profiles_table
categories_table
When executing php artisan db:seed command I'm getting the following error:
C:\xampp\htdocs\photoblog-master\photoblog-master>php artisan db:seed
Seeding: UserTableSeeder
[ErrorException]
unlink(C:\xampp\htdocs\photoblog-master\photoblog-master\public\uploads/user-picture\61224db90375756038856cd51e1c48a7.jpg): Resource temporarily unavailable
Would you please tell me how can I solve this error?
Is the file C:\xampp\htdocs\photoblog-master\photoblog-master\public\uploads/user-picture\61224db90375756038856cd51e1c48a7.jpg in use?
I have a similar issue when I opened a file and tried to delete it without fclose it first.

Laravel migrate unknown database

I am having some errors with laravels php artisan migrate command, when I try to migrate, it keeps throwing errors saying, unknown database 'database name'
I have checked my database configure file and even copied to a different project and it works perfectly there, I have tried composer dump-autoload command but that didn't solve the problem either. Please I will really appreciate if someone helps, since this is a new project and can't afford to lose even a minute to my deadline, thanks in advance!
The command I run from the terminal while I have CD'ed into the project folder is.
php artisan migrate
This is the error I get.
[PDOException]
SQLSTATE[42000] [1049] Unknown database '[gicfamily4]'
[PDOException]
SQLSTATE[42000] [1049] Unknown database '[gicfamily4]'
This is a MySQL error and is indicative of either a misconfiguration in your environment's database.php config file (misspelling in the database name) or the database gicfamily4 simply doesn't exist on the database server you are connecting to.
Verify your connection information again. If possible, try to attempt to connect to the mysql server from the command line using the exact same information contained in your database.php file (via copy and paste):
$ mysql -u <username from database.php file> -p -h <database host from database.phpfile>
Enter Password: <paste password from database.php file>
mysql> use gicfamily4;
I suspect you will get the exact same error as above.

Categories