I am getting this error and any help would be greatly appreciated.
I am using mongo db as my default session database. Laravel seems to try to insert session data in table every page visit with the same session Id which generates duplicate index error.
I created my sessions table using:
php artisan session:table
composer dump-autoload
php artisan migrate
and then I set the correct properties in the app/config/sessions.php.
The first session value gets inserted correctly in the table but there is an error of duplicate index error on page refresh or redirect.
Please help.
Thanks.
I resolved the error by executing bd.sessions.drop() on the database.
https://github.com/kcbanner/connect-mongo/issues/78
The problem resolved immediately.
Related
I'm not a Laravel developer, but I bought a website from CodeCanyon, and this is the error I'm getting.
SQLSTATE[42S02]: Base table or view not found: 1146 Table
'ahimalayan.localizations' doesn't exist (SQL: select * from
localizations where ip = 223.185.4 limit 1)
And the service provider is not answering much, and I need to upload it asap but he told me to use php artisan migrate:fresh—seed, but I'm not sure where to use it and how to use it. Can anyone please help? I'm a little bit friendly with coding.
I suggest this steps for your problem :
you need to create a new database in host control panel
Rename example.env file name to .env in main root folder and put new database data inside that. just like this:
DB_DATABASE=DB NAME
DB_USERNAME=DB USERNAME
DB_PASSWORD=DB PASSWORD
then add this line inside routes/web.php file:
Route::get('migrate', function() {
\Illuminate\Support\Facades\Artisan::call('migrate:fresh -—seed');
});
now open this url on your browser to run migrations and seeds. then all required tables will be created automatically and some demo data will be inserted as well.
http://localhost/LaravelFolder/public/migrate
You likely need to run these 2 commands in your app root path.
php artisan migrate
php artisan db:seed
I'm trying to do a rollback in Laravel 5.4. I deleted a file manually from the migrations folder. Now when I try to rollback I get an error:
[root#xxx]# php artisan migrate:rollback
[ErrorException]
Undefined index: 2017_08_22_204640_create_tasks_table
That file was a test (with a controller and a view), but I'm new on Laravel and didn't know that deleting that file manually would be a problem.
How can repair that now?
Edit: The main goal is to rename a column from a table made with migrations.
I made this migration file:
[root#xxx]# php artisan make:migration rename_nombre_generadora_column --table="admin_generadora" --create
Created Migration: 2017_08_24_160600_rename_nombre_generadora_column
But then I saw that the name of the table was wrong, should be admin_generadoras. I wanted to create a new migration file but I got this error:
[root#xxx]# php artisan make:migration rename_nombre_generadora_column --table="admin_generadoras" --create
[InvalidArgumentException]
A RenameNombreGeneradoraColumn migration already exists.
So how can I undo that migration?
In situations like this I always tend to simply delete whole database and run "correct" migrations again. You have seeds right? You have factories right?
I copy some text I have written before:
Note for migrations and how to do it right (IMHO):
always use migrations to create and update database schema
if you are a lone developer AND there is no production environment set up, just amend the migrations and do database reset (remove all tables) + migrate
if you are a team OR there is production environment already set up, always create new migration
do not bother with down() method that much
Some material from creator & friends of Laravel regarding migrations can be heard in this podcast http://www.laravelpodcast.com/episodes/68236-episode-53-bigger-better around 30 minute mark.
What you need to do now is to understand deeply how migrations work! To do that you need to take a look at migrations table and play with it; play with artisan and migrations related commands. And remember you can update/amend database schema with SQL (that means using some kind of database client like PhpMyAdmin) but also amend/update corresponding migration.
the --table flag just helps you fill out the migration file faster. Just go in to the RenameNombreGeneradoraColumn file and change admin_generadora to admin_generadoras
I am having a problem when trying to make migrate.
MY DATABASE DOES NOT RECEIVE NEW MIGRATION, NO NEW FILES NO UPDATES
From my project;
I do:
php artisan migrate
But nothing shows in my database, I already verify my database and my file .env
Both are correct.
I know you said you verified it, but please check again that the correct database information is entered in your .env file. It should be something like the following for a dev environment:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
You need to edit that data if you haven't and make sure it's correct. You also need to make sure that your database actually exists.
Also make sure you're actually entering the correct command. The general way you should making migrations is:
php artisan make:migration create_example_table --create=example
After that, run
php artisan migrate
Lastly, are you getting any errors in the console? If so, you need to edit your post and post them here.
firts thanks for answering
I had already checked .env file and I replaced database name from my sql (I use phpadmin), and also I changed username and password as I entered on sql server, but there is no migration
I had created a new table using artisan command (besides I have a users table that comes when downloading laravel project). After creating this new table I expected to upload this new one to my database located in sql server, but nothing happen
it shows your users yable already exists, mentions my users tables and not my new table that i just created. It is weird bcz it does not EVEN upload any changes made in default table users.....always answer your table users already exits
I'm new with laravel, I read the documentation of laravel, but I don't know how I make an authentication with a real mysql database.
I mean, I see that there is a php migration command, but it makes a table in php and not in my database right ?
Actually, I have a mysql database with a user table with login and password.
I'm lost with this framework, because I never used a php framework.
Thanks !!
Edit :
Excuse me, I misspoke and my problem has evolved, how did you to authenticate with a user table already exists in the database by using the Authentication service?
in .env or config>database.php you can set your database and related database connections configurations
after that create migrations and run them it will create database tables in your database as per your .env or config>database.php database configurations.
I think you might need to read again Laravel documentations.
Try the following.
Make sure you have a database create in your MySql.
Check again your .env for: database_host, database_name, database_user, database_password - make sure you have the right
Try bellow code on your route.php
Route::get('/', function () {
if(DB::connection()->getDatabaseName())
{
echo "Yes! successfully connected to the DB: " . DB::connection()->getDatabaseName();
}
});
If above is successful your migration should work.
I want to use Laravel Database Session. I have changed
'driver' => 'database',
in session.php.
When I try to access application i.e during landing page or before login
I am getting this error
null value in column "data" violates not-null constraint DETAIL
But if this error comes after login, then it is fine. Because that is when session is created. I did not understand why it is coming during application load.
Please let me know what is the issue or Please let me know the tutorial link for session handling in Laravel4
Thanks all
The "data" value you reference doesn't exist in the implementation of the Laravel session handler. The fields are id, payload and last_activity.
If you're trying to use Laravel's session handler via database, you're going to need to run the Laravel migrations.
Go to your command line and run artisan. php artisan session:table will automatically create the Laravel session migrations.
Then run composer dump-autoload or composer.phar dump-autoload (depending on your implementation).
Next, php artisan migrate and your Laravel session table will be created! You'll now be able to use laravel's built-in session handler.
Documentation here: http://laravel.com/docs/session#database-sessions