PHP script MYSQL database to migration in laravel 5.1 - php

I have MYSQL database.
How can i convert database to migration on laravel 5.1
Any body have script?

In order to generate migration files based on existing database structure you can use one of available Laravel packages. I've used Xethron/migrations-generator in one of my projects - you can find it here: https://github.com/Xethron/migrations-generator.
There are some small issues running it with Laravel 5.1, but they are easy to solve - you can check the discussion here: https://laracasts.com/discuss/channels/general-discussion/laravel-5-migrations-from-existing-database?page=1 - one entry needs to be added to your composer.json.
Once you have the package properly installed and configured, make sure you have correct database credentials in your database.php config file and then run php artisan migrate:generate and migration files will be generated.

Related

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

How to create a build update in laravel?

I want to know there is any way by which we can create a installer or some package for laravel application by which user can simple paste file and deployer will ask for db host and other setting and install application.
Also is there anyway by which we deploy a new build in current application and it will have all new updates which may contains updates in previous table. We want to keep data safe and release updates.
Got help from this answer
Install
To create installer for your application, you can Laravel-Installer package.
This package has following features:
Check For Server Requirements.
Check For Folders Permissions.
Ability to set database information.
.env text editor
.env form wizard
Migrate The Database.
Seed The Tables.
Update
Updating your database mean needs to migrate your database. You can run your migrate command through your application.
Run migration command from anywhere
Artisan::call('migrate');
With using route:
Route::get('/run-migrations', function () {
return Artisan::call('migrate', ["--force"=> true ]);
});

Laravel migration deployment

Just a quick one really
I have an existing Laravel app
I want to use a migration to add some columns to an existing table
So i do the following:
php artisan make:migration add_columns_to_table
Which creates a file in my migrations folder called:
2017_10_25_124938_add_column_to_table.php
And also creates an entry in my migrations table in the database. All good.
I can edit the migration file (adding the columns etc) and run
php artisan migrate
And everything works great
Now - my question is this:
When i come to deploy to live i am presuming I would log onto the live box and run the create migration command again:
php artisan make:migration add_columns_to_table
But this will create a migration with a different name to the one i created / tested locally?
So - do i then need to manually copy the code from my local 2017_10_25_124938_add_column_to_table.php migration file to the one created on the live box?
That seems a bit backwards and fiddly
What is the best way of creating and testing a migration locally and then deploying it to live when the create migration command creates a different named migration file (and DB entry) on the live box?
Or have i got the wrong end of the stick?
The best practice is to keep migration files with the repo. While deploying the application on any environment you have to execute all migrations.
php artisan migrate
This command will run all the migrations which are not already executed in the current environment. Laravel use a table called 'migrations' to keep track of all the migrations it has run.

Database setup for Cartalyst/Sentinel

https://cartalyst.com/manual/sentinel/2.0#sentinel-authenticate
I've followed the basic installation in the Sentinel documentation for Native usage as I don't have Laravel installed, I have installed all the packages via Composer and I'd like to start doodling with Sentinel to test it before using it into production. My problem is I don't know how to setup MySQL/MariaDB for tables Sentinel will use, in fact I got an Exception like this
SQLSTATE[42S02]: Base table or view not found
Some other packages give the basic SQL file to import, but I don't know how to deal with database setup for Sentinel, please help!
There is a schema folder here: https://github.com/cartalyst/sentinel/tree/2.0/schema
You can find a mysql.sql (or mysql5.6+.sql) script to create your tables.

How I can install and configure an existing Laravel Project? (Laravel 4)

I need to install and configure an existing Laravel 4 project.
I tried to do, but when I ran composer update or composer install a lot of issues appear.
I have the database too (with data) so I ran the migration but doesn't work because the console show me an issue about the "table doesn't exist".
Can anyone tell me the complete process to configure the App?.
I mean, what its first, second and so and so because maybe in some step I made a mistake
To install and configure an existing project, you'd typically
Check out its source code
Run composer install
Run php artisan migrate
Check the README for specific instructions on installing 3rd party assets, or any additional steps you'd need to take
If the above creates errors, its either because of something in your environment (installing over an old project?) or some problem with the way the Laravel developer created their project.
To install and configure an existing project, you'd typically check those things first :
You should goto app/config/database.php check file and verify username and password.
After check in Project Folder vendor folder and composer.json file exist then remove it (that remove old configuration now we going to fresh configuration).
Then after back to command prompt and fire command composer update and that download some dependent file download.
Now Run php artisan serve
that tricks work for me last time when I migrate another host.
Carlos, when using an existing DB you'll need to check the migrations table to see which migrations have run successfully. Typically when taking over a laravel project setting up a new db and running the migrations against it is a good idea because you never know what hacks were made to the database outside the migration system. One small change can throw the entire system into a useless state because it's looking for a table or column that doesn't exist or has been modified. If you run the migrations against a bare db you can also figure out which tables were manually created (which could very well be your issue) outside the system and add them in as necessary. Cobbling things together after a previous developer is tedious, hopefully there is decent documentation.
Note that if you are using Git with .gitignore, don't forget to copy .env variables in new location too.

Categories