I found a Laravel 4 announcement on HN a few weeks ago and thought I could give it a try.
After looking for a basic tutorial, I found this one:
http://www.codeforest.net/laravel4-simple-website-with-backend-1
And ran into what is probably a silly problem: the command php artisan migrate --package=cartalyst/sentry created a single table in my database when it should have created four, according to the tutorial.
Is there some step missing, or did I assume wrong when I thought it had something setup to create the needed tables?
Looking at the Sentry home I couldn´t find what I did wrong, so I´ll just look for the SQL to create the tables in the source, but I still would like to know what was the problem.
First run
php artisan migrate
Then run
php artisan migrate --package=cartalyst/sentry
After doing this it should create these tables: migrations, groups, throttle, users, user_groups
If fails again, destroy your database, re-create and re-run these steps.
Related
I have a Laravel application that uses a DB. The DB is big and was produced by many migration files. Is there a way to cut down the number of migration files so that each table has one migration file? Also Would something results from having too many migration files? like performance issues?
if you have laravel 8 you can use squashing-migrations
by run php artisan schema:dump cmd
ref link https://laravel.com/docs/8.x/migrations#squashing-migrations
for older version you can try this
https://github.com/Cytracom/laravel-migration-squasher
or you can try this
Laravel 5.5 Consolidate migrations w/ production database
after laravel 8 you can run php artisan schema:dump
it change all migrations to single schema file
For more explanation check link https://advancedwebtuts.com/tutorial/what-is-the-use-of-laravel-squashing-migrations-schema-dump-command
I have two Laravel projects, one for client-facing (let's call this project A) and the other one for admin (let's call this project B).
If I update database, such as creating new table or adding extra column on existing table, using Laravel migrate from the project B, is there any action required on project A side?
Thank you!
You can create the first_migration in project A and excute it, and then, create the second_migration in project B and excute it, you will find the migrations are work as expected.
But...when you try to rollback the migrations in any of the project, you might get a Migration not found error, due to the rollback action will call the down method in each migration files which had migrated, but project A or project B has part of all migration files.
So, you might put all your migration files together by using --path:
php artisan make:migration foo --path="../projectB/database/migrations"
# or
php artisan make:migration foo --path="/the/absolute_path/to/projectB/database/migrations" --realpath
# migrate
php artisan migrate --path="../projectB/database/migrations"
# migrate:rollback
php artisan migrate:rollback --path="../projectB/database/migrations"
If you go into your database and do select * from migrations that should help you see what the artisan migrate command is referencing to decide whether to run migrations.
I'll just think it through with you:
If you create a migration in project A and run it, it will update your database and the migrations table in your database will record that the migration has been run.
Project B isn't going to have that migration in its own database/migrations folder in the app. So if you do artisan migrate --pretend the reality is its going to find entries in the migration table which it has no record of as migration files in its own database/migrations folder.
I'm not actually sure what it would do there.
But having a single database used by multiple apps is definitely a reasonable thing you're trying to do here. It's normal practice.
Why not just decide which app, A or B, you are going to make responsible for holding all migrations and know that you'll only ever do artisan make:migration and artisan migrate in, say, project A, and just consider project B to be a second client of the database which project A actually "owns"?
So, given the above, the answer to your question I think is no. You don't have to use the migration system in a laravel app. You can just as well connect to a database and assume that whatever tables your code wants are already there, which would be what your project B would do.
(But it might make sense to have your admin side be the owner of the database migrations (which you actually called project B above)).
Also obviously if using eloquent then both projects are going to need the respective eloquent models. You'll have to duplicate that code at least.
I have follow the laravel migration steps and its good. My problem is about on modifying the column. I already installed the doctrine\dbal in composer. But when i change the column $table->string('name')->nullable()->change() with change method, then run php artisan migrate. Is says nothing to migrate. Why? Do i need to use the doctrin\dbal like this use Doctine\dbal in the migration table class? Or what is the better way to implement for modifying the table column in migration and what artisan should i run? Any help please!
Tenancy migrations will only run once, meaning once it has been run, it will not run again once the php artisan migrate has been run. You can see all migrations which have been run in your application by viewing the migrations table in your database.
If you edit a migration file and need to re-run all your migrations you can use the following command php artisan migrate:refresh. This will rollback all your migrations and re-run them and also increment the batch number on the migrations table.
If you need to edit one of your tables but don't need to re-run all your migrations, you should create a new migration and edit the table in question in that particular migration. Once the migrate command has been run again, only your new migration will be executed.
You can find more information on all of this in the following link: https://laravel.com/docs/5.4/migrations
I have a database and I would like to generate migration based on tables that already exists.
How can I do that?
I am running linux ubuntu 16.10 + Mariadb and laravel 5.4
A quick Google shows many packages that will do just this sort of thing for you, like migrations-generator.
You'll probably want to go over any generated migrations as well just to make sure they match what you're after.
I am having a very bad situation here, working on a Laravel 5 project. previously developed by another developer. That developer at start created couple of tables using migration generators and added some columns using migrations. After that, he added table columns straight away using some sql GUI. I was given the sql dump which i imported and set it up on my local machine, now when i created a table using php artisan make:migration create_myTableName_table --create="myTableName" the table migration is created successfully, but, when i did php artisan migrate it's giving me SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'someTable' already exists I checked migrations folder and matched it with current version of someTable and i can see the columns are different, same with other tables aswell.
What should be the best case to handle this in this situation, i want to keep up with Laravel migrations generator so that in future if any other developer want to work on this project he just has to run migration command to migrate database or to create tables or create columns... Should i re-write all migrations ? pleas help. Thanks
Given your situation, I’d put the .sql export in your repository, clear out the old, broken migrations, and create a new one that initially imports the database dump. Then just create migrations as normal going forward.
Quick and dirty?
Delete current migration files. Clear your migrations table and export the whole DB. Put the SQL dump in the repo and instruct other devs to import it before they run php artisan migrate. With the dump imported and migrations table truncated, you can create new migrations with no further collisions with the legacy migrations.
Feeling ambitious?
Use a package like migrations-generator to generate migrations based on your current DB structure. Then, migrate away.