Tables not migrating into database using Laravel - php

I am new in Laravel and i am using "Laravel version 9" (latest),I run following command
but giving me following error
Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
i had 4 files inside "database/migrations" then i run "php artisan serve" command but only "two tables" inserted into database (users(empty) and migrations),how can i add rest of tables ? I tried with following code inside "/app/Providers/AppServiceProvider.php" but still getting same error,How can i fix this ?
public function boot()
{
Schema::defaultStringLength(191);
}

In your file config/database.php, find key mysql and add line
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
Should look something like this :
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_AUTO_CREATE_USER',
'NO_ENGINE_SUBSTITUTION'
],
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC', // this line
],

Related

How to figure out my dump_binary_path in my device? Using spatie laravel-backup package for Laravel 9

I'm currently using the spatie laravel-backup for backup my database.
But when I execute the command
php artisan backup:run
I get this error :
Backup failed because The dump process failed with exitcode 1 : General error : The system cannot find the path specified.
After my research, I tried to change my dump_binary_path to 'D:\xampp\mysql\backup\mysql' but it still not working. Therefore I'm thinking that I might have entered the wrong path .. is there a way to find the path?
Here is my code in config/database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'dump' => [
'dump_binary_path' => 'D:\xampp\mysql\bin',
'use_single_transaction',
'timeout' => 60 * 5, // 5 minute timeout
],
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Any answer and suggestion are higher appreciated
I have same problem. But I solve it from this step. you can also try.
follow this step
https://spatie.be/docs/laravel-backup/v5/installation-and-setup#dumping-the-database
then add
'dump' => [
'dump_binary_path' => 'F:\xampp\mysql\bin',
],
Then click your comment link.

SQL SSL errors when deploying laravel project to azure

I deployed the project to azure and both the webpage displays properly and links work fine, but for the user registration I need to connect the database. Everything works well locally and I followed all the instructions of creating/connecting a sqsl db in azure but I get thte following 3 errors and not sure what to do, how to debug, its a project I was given to deply and didnt create myself,( I am only gona show the first 3 lines of the error since they are long):
UPDATE: It works if I disable the SSL on azure so its got something to do with my local app config for that
1-
SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL options and retry. (SQL: select count(*) as aggregate from `users` where `email` = ***#***.com)
in Connection.php line 647
at Connection->runQueryCallback('select count(*) as aggregate from `users` where `email` = ?', array('***#***.com'), object(Closure))
in Connection.php line 607
2-
(2/3) PDOException
SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL options and retry.
in PDOConnection.php line 50
at PDOConnection->__construct('mysql:host=***.mysql.database.azure.com;port=**+;dbname=uwiredb', '***#***', 'MySQLAzure2017', array(0, 2, 0, false, false))
in Connector.php line 65
at Connector->createPdoConnection('mysql:host=***.mysql.database.azure.com;port=***;dbname=***', '***#***', 'MySQLAzure2017', array(0, 2, 0, false, false))
in Connector.php line 44
3-
(1/3) PDOException
SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL options and retry.
here is the DB section of my .env file:
DB_CONNECTION=mysql
DB_HOST=mydbserver.mysql.database.azure.com
DB_DATABASE=mydb
DB_USERNAME=myuser
DB_PASSWORD=mypass
MYSQL_SSL=true
And here is the connection part of my database.php file in the config folder, I know the hosts
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'sslmode' => env('DB_SSLMODE', 'prefer'),
'options' => (env('MYSQL_SSL')) ? [
PDO::MYSQL_ATTR_SSL_KEY => '/ssl/BaltimoreCyberTrustRoot.crt.pem',
] : [],
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
],
I know the host is set to local but that is how I understood it should be from the azure docs that say:
You can use the PHP getenv method to access the settings. the Laravel code uses an env wrapper over the PHP getenv. For example, the MySQL configuration in config/database.php looks like the following code:
PHP
Copy
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
...
],
Thanks

Error: [InvalidArgumentException] Database [fooBar] not configured Laravel 5.4

I'm trying to write a migration for a new table.
public function up()
{
Schema::connection('fooBar')->create('tableOfThings', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
}
But when I run php artisan migration, I get the following error.
[InvalidArgumentException]
Database [fooBar] not configured.
This is what I have in config/database.php. You can see that I do infact have this DB configured.
'connections' => [
'foo_bar' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 3306),
'database' => 'fooBar',
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
// ...
]
Make sure the name of the configuration (not the database) is what you are passing to the connection.
DB::connection('foo_bar');
'connections' => [
THIS 'foo_bar' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 3306),
NOT THIS 'database' => 'fooBar',
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
// ...
]
You are trying to connect to the fooBar connection, but your connections array doesn't have that connection. It's called foo_bar instead.
Either change your connections configuration to fooBar or your schema connection call to foo_bar.
'connections' => [
'fooBar' => [ // Changed from foo_bar to fooBar.
// ...
],
// ...
]

Laravel switch mysql to mongodb

After completed my project I deiced switch mysql to mongodb. I am using Laravel 5.4 version and for mongodb use jenssegers. For laravel mongdb installation I follow jenssegers installation documentations and installation successfully completed. But after installation I go for migration and use command php artisan migrate. When I use this command shown error InvalidArgumentException in /vendor/mongodb/mongodb/src/Database.php line 83: $databaseName is invalid:
My database.php
'default' => env('DB_CONNECTION', 'mongodb'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE', 'project_db'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'options' => [
'database' => 'admin' // sets the authentication database required by mongo 3
]
],
],
My .env
DB_CONNECTION=mongodb
DB_HOST=localhost
DB_PORT=27017
DB_DATABASE=admin
DB_USERNAME=
DB_PASSWORD=
And I also facing one more problem if whatever I change in .env and database.php like if I change port 27017 to 3303 but on browser shows 27017. I cleared cache and all. I don't know what is problem in my code.
These are the steps Envoyer (made by Laravel's creator) takes to deploy an app on production -- I've annotated them below:
# Clear the old boostrap/cache/compiled.php
php artisan clear-compiled
# Recreate boostrap/cache/compiled.php
php artisan optimize
# Migrate any database changes
php artisan migrate

connection laravel and oracle by yajra

I almost gave up, before there is no problem but after I reinstall the oracle why laravel can't connect.
This error as I can when running the migrate:
c:\xampp\htdocs\tester>php artisan migrate
[Yajra\Pdo\Oci8\Exceptions\Oci8Exception]
ORA-24315: illegal attribute type
file .env ->
DB_CONNECTION=oracle
DB_HOST=127.0.0.1
DB_PORT=1521
DB_DATABASE=corsys
DB_USERNAME=tester
DB_PASSWORD=orcl
oracle.php in the folder config ->
<?php
return [
'oracle' => [
'driver' => 'oracle',
'tns' => env('DB_TNS', ''),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '1521'),
'database' => env('DB_DATABASE', 'corsys'),
'username' => env('DB_USERNAME', 'tester'),
'password' => env('DB_PASSWORD', 'orcl'),
'charset' => env('DB_CHARSET', 'AL32UTF8'),
'prefix' => env('DB_PREFIX', ''),
'prefix_schema' => env('DB_SCHEMA_PREFIX', ''),
],
];
please help me :(
You need to enable your oracle driver for PHP to be able to access your oracle database.
Related answer here:
https://stackoverflow.com/a/26213384/1739852

Categories