Laravel migrations with multiple sites and DB's on my homestead - php

So I have set up my homestead so that I have two sites with two separate DB's. I can go to both sites separately when I run homestead up and can make changes to one site separately from the other. But when I try to do a simple migration of the in box create_user_table on the 2nd site it says there is nothing to migrate. I run migrate:status and it says both migrations (create_user_table and create_passworde_resets_table) have been made but nothing is showing up in 2nd my database.
I have a hunch that my 2nd site is still pointing to the first DB because when I run migrate:rollback I get a message that a class from my other project can't be found. How can I point my 2nd project at my 2nd DB?
p.s. I know the 2nd DB exists because I used sequel pro to login to my VM and I see that both DB's are there

Ok I figured it out. I had to go into my .env file and edit the DB_DATABASE variable to the proper database name.

Related

Work in teams using MySql and xampp localhost - can't update the database

Me and some friends are working on a PHP page and we need a MySql database(we need to present the xampp localhost version). Since we will all make edits there we need a way to somehow update our local database with others work when they do it.
I tried to export the database from them and import in my phpmyadmin but for this I have to delete my old database. Isn't there a method to just update it? I mean what can they make to send me a file with an update and how can I import just an update?
I tried to search the answer for hours but couldn't find something specific.
I think the main problem is to synchronize database table changes, not data.
You must read about migrations and don't interact database directly from PHPMyAdmin.
Phinx is the most popular tool in PHP about migrations.
https://phinx.org/

Laravel, migrate existing table from local phpmyadmin to server

Im new to laravel, someone asked me to modify in his project, these modifications need to have new tables, I created tables directly on phpmyadmin, these tables include countries and regions tables which have huge rows, I wanted to push the project to the server but don't have access to the database so must using migrate, my questions are:
how can I migrate the tables I created in phpmyadmin? I didnt create tables using the command artisan migrate.
how can I push countries and regions tables contents?
thank you in advance
Firstly familarise yourself with the documentation on Laravel Migrations (https://laravel.com/docs/6.x/migrations). The documenation is excellent!
If you want to replicate the structure of the table you have already created, I would start by getting the table schema from phpmyadmin and then simply walking through it line by line and finding the appropriate methods in the documentation.
Once you have matched the table structure, it then just a case of taking a database dump of your existing table and importing it.
To update the production server database you still can use migrations, even if you created tables manually on local environment.
Please read the docs for more info.
Run the command: php artisan make:migration table-name in local environment, and write required columns in created file.
After that, you can upload this file on the server and just run: php artisan migrate this will create tables on the prod database.
To automatically insert data after migrations you can use seeding: https://laravel.com/docs/5.7/seeding
This is not a correct approach, If you are using Laravel and manually uploading the data.
The better solution is to write the migrations and seeder.
You can print db result in an array and paste everything in your Seeder file, Check the syntax on Laravel website

Migrations Table Empty - Can't run php artisan migrate

So, I've copied a database off a server that I'm working on and I've just started working on it. However for some reason the migrations table is empty so when I try to run php artisan migrate it can't because it doesn't know that all the tables are already created. Is there a quick way of fixing this rather then adding in the name of every migration to the table manually as there are a lot of migrations in this project?
Thanks.
You can work around it the following way:
Create another empty database.
Switch your application to use the new database.
Run php artisan migrate
Copy migrations table from new database to the old one
Switch your application to use the old database again.
You could also delete existing migration files (bad idea) or move them to some other folder so that migrate command doesn't see them.
You could also fill the table yourself, but that seems pretty time consuming.
Why is that table empty in the first place? Is it empty on your server as well?

Illuminate Database outside Laravel with Phinx for migrations

I'm working on a project where I'm using Illuminate's database component outside of Laravel 4.2 and trying to use Phinx for migrations from the command line. I've set up my database environments in the phinx.yml file for production, development, and my local, which I named "vagrant". When I try to run the "php vendor/bin/phinx migrate -e vagrant" it comes backs saying "Could not determine database name! Please specify a database name in your config file." I've tried multiple times to figure out what's causing it, the database name is correct. Any ideas?
Thanks!

Trying to re-run laravel migrations in laravel after dropping all tables in db but my xampp sql connection will unexpectedly close during migrating

So basically I changed something in a migration in my laravel project and then tried running migrate:refresh and migrate:reset etc but was getting errors with files not found, so I dropped all of the tables in the phpmyadmin database and attempted to re-migrate.
So initially in the CMD it will say 'migration table created successfully' and then will do nothing else for a couple of minutes, after some time the xampp sql connection will close, giving an error 'Error: MySQL shutdown unexpectedly.'
So I restarted the sql server in xampp and checked the database and some of the migrations have run but not all of them, and the number it runs varies, sometimes it will make 7 of the tables, other times 15 but never does it create all of them successfully before the sql server shuts down.
I am working on a project in a team and this issue seems to be affecting only 2 out of 8 of us, for everyone else the migrations run perfectly after dropping all the tables and they have the exact same copy as me as we are using GIT.
I have tried:
Reinstalling xampp & composer,
re-making every single migration,
and re-cloning my repository from bitbucket.
I've asked around at work and no one seems to have seen this error/issue before so any help at all would be greatly appreciated.
Cheers,
Sam.

Categories