Category : database-migration

I’ve got these two tables linked with a one to one relation. How should the seeders be if I want unique foreign keys in sponsored apartments table? Model table Apartments: public function sponsoredapartment() { return $this -> hasOne(SponsoredApartment::class); } Model table Sponsored Apartments public function apartment() { return $this -> belongsTo(Apartment::class); } Migrations Apartments Schema::create(‘apartments’, ..

Read more

First migration file: <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; class CreateUsersTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create(‘users’, function (Blueprint $table) { $table->id(); $table->string(‘name’); $table->string(’email’)->unique(); $table->timestamp(’email_verified_at’)->nullable(); $table->string(‘password’); $table->rememberToken(); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function ..

Read more

Migration file: <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; class CreatePostsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create(‘posts’, function (Blueprint $table) { $table->bigIncrements("post_id"); $table->bigInteger("author_id"); $table->string("title"); $table->string("short_title"); $table->string("img")->nullable(); $table->text("descr"); $table->timestamps(); $table->foreign("author_id")->references("id")->on("users"); }); } /** * Reverse the migrations. * * @return void */ public function ..

Read more

I’ve been watching a tutorial on Laravel and there is $table->bigIncrements("id") in a migration file, but when I open the same file there is $table->id() function. Questions: Was there any update in which bigIncrements was replaced by id()? I’ve been searching the net for a while but haven’t found anything about it. Do these functions ..

Read more

I set commission default as 0.00. But when I insert the data but don’t give any on commission. it’s giving an error that commission can’t be null. *Here is my migration code:* public function up() { Schema::create(‘pc_lists’, function (Blueprint $table) { $table->bigIncrements(‘id’); $table->string(‘name’)->nullable(); $table->decimal(‘commission’)->default(‘0.00’); $table->tinyInteger(‘status’)->default(‘1’); }); } *My blade code is here:* <div class="card-body"> <form ..

Read more

I have added a new column to a database table using Laravel migration as follows: <?php use IlluminateSupportFacadesSchema; use IlluminateDatabaseSchemaBlueprint; use IlluminateDatabaseMigrationsMigration; class AddFAQToStoreTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table(‘store’, function (Blueprint $table) { $table->longText(‘FAQ’)->after(‘description’); }); } /** * Reverse the migrations. * ..

Read more

I have a project on which I need to run php artisan migrate. It should be ease but I am getting an error php artisan migrate IlluminateDatabaseQueryException SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘skz.master_courses’ doesn’t exist (SQL: select * from master_courses where date_from > 2021-06-01 and master_courses.deleted_at is null order by date_from ..

Read more

Im using Spatie Multitenancy package v2.0 with laravel 8 and php 8. I have followed the documentation and when i try to migrate the file in my landlord subfolder of migrations, (which does contain the create landlors tenants table), using php artisan migrate –path=database/migrations/landlord –database=landlord it returns migration table created nothing to migrate, even though ..

Read more

When i use php artisan schema:dump –prune it causes an error. I have mentioned the username in my database.php but it still gives an error. Can anyone help me? Undefined variable: username at vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:41 37▕ */ 38▕ public function createConnection($dsn, array $config, array $options) 39▕ { 40▕ [$username, $password] = [ ➜ 41▕ $config[$username] ?? ..

Read more

this image is show the my problem i want try to type of payment in database any body can help me public function up() { Schema::create(‘gems_stats’, function (Blueprint $table) { $table->id(); $table->integer(‘userid’); $table->string(‘event’); $table->string(‘type’); $table->integer(‘closing_bal’); $table->time(”); }); } Sourc..

Read more

When I do a migration by using the command php artisan migrate I have this error: In Macroable.php line 104: Method IlluminateDatabaseSchemaBlueprint::id does not exist. I don’t understand where this error arises from. Do you have an idea please? <?php use IlluminateSupportFacadesSchema; use IlluminateDatabaseSchemaBlueprint; use IlluminateDatabaseMigrationsMigration; class CreateFilesTable extends Migration { public function up() { ..

Read more

I am using Laravel 8 in one of my projects. I have created a Model with migration and I have specified which connection to be used in the Model file, which is as below: <?php namespace AppModels; use IlluminateDatabaseEloquentModel; use IlluminateDatabaseEloquentFactoriesHasFactory; class Model1 extends Model { use HasFactory; protected $table = ‘table1’; protected $connection = ..

Read more

Laravel ships with database migrations for managing CRUD operations regarding the structure of a database, but what is the appropriate/recommended/standardized way to handle migration of actual data? As an example, Laravel ships with a user table migration that has a name column. Let’s say the application is already in production and uses the basic name ..

Read more