#### 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’, ..

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 ..

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 Problem Background: In my DB we are migrating data from MSSQL to MySQL, now while migrating we ned to escape various strings as there are many html contents and other contents which need to be escaped. Real Problem: Now all the text strings have / (slash added) to them I want to remove these after .. 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 ..

I have seen all of the other questions in this website and the solutions does not work in my case. I am using a Mac, Laravel development server: http://127.0.0.1:8000 and in XAMPP I am using localhost:8080 -> 80 (Over SSH). I have created a new database in PHPMyAdmin called posty which corresponds to the database ..

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. * ..

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 ..

These are the images .env file mysql error Sourc..

We’re using Laravel Migration (v8.x) to alter one of our existing tables, where we want to rename a column to an existing column, but before that, we dropped it. On up() it’s working just fine. But on the down(), it cannot rename the columns first and then cannot add the column. The following code is ..

I am trying to create a command to perform all the migrations I have at once but in a way that assigns each of them to a different batch. As a first attempt, the command I have created contains: class CreateDBStructure extends Command { protected $signature = ‘database:create’; … public function handle(){$this->call(‘make:migration’, [ ‘–path’ ..

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 ..

I’m working on a function that triggers after a new row is added to the table. The function tends to combine two different values from two different tables with a value from the table where the new row goes. The migration looks like this DB::statement("CREATE OR REPLACE FUNCTION potatoes.name_work_order() RETURNS trigger LANGUAGE plpgsql AS  ..

using MySQL database and has PHP 7.4* IlluminateDatabaseQueryException SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: YES) (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = ‘BASE TABLE’) Sourc..

i’m trying to make a migration using Laravel. The idea is to get the values of columns ‘code’ and ‘id’ in different tables, and merge them into a column ‘name’ with ‘-‘ separators. So in part it is a SQL problem. Currently i’m trying something like this. First migration to create the new column ‘name’ ..

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 PHP Version => 7.4.1 Laravel version => 5.2 I run command composer install but it returns this error, can anyone please help. composer.json looks like below Sourc.. 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..

when creating a new product, the user could add more than one size, I want each row to be added in the sizes table, where the foreign key is product_id How should I do that in the product controller? this is the products controller public function store(Request $request) {$validatedData = $request->validate([ ‘moreFields.*.designation’ => ‘required’, .. Read more I’m new in Laravel world! I created a Database in MySql with 8 Tables! now i just want to know that do I need to create Migration for all 8 tables? or just need to create model for each table? 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 = ..