-2

pic1

pic2

Pic 2 is the usual laravel migration tables that i created. Pic 1 is the laravel migration tables that i newly created. They have the same code with same foreign key only with different attributes name. Why is pic 1 only have varchar(191) instead of varchar(255), and the foreign key doesnt apply from migrations anymore? Before pic 1, i did ran some stuff on terminal for deployment purpose like npm build. Is the terminal the cause of this?


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('calibrations', function (Blueprint $table) {
            $table->id();
            $table->string('Identification_No');
            $table->foreign('Identification_No')->references('Identification_No')->on('fieldequips');
            $table->string('Calibration_point');
            $table->date('Expired_Date');
            $table->date('Calibration_Date');
            $table->date('Next_Due_Date');
            $table->string('Correction_factor');
            $table->string('Validated_by');
            $table->date('Validated_Date');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('calibrations');
    }
};
steven7mwesigwa
  • 5,701
  • 3
  • 20
  • 34
ggcode
  • 13
  • 5
  • Where is the database migration source code you're referring to? – steven7mwesigwa Nov 08 '22 at 04:40
  • I added the code, but i dont think its the code problem because it works perfectly fine days ago – ggcode Nov 08 '22 at 04:50
  • [MySqlBuilder::defaultStringLength()](https://stackoverflow.com/questions/52967229/mysqlbuilderdefaultstringlength) – steven7mwesigwa Nov 08 '22 at 04:57
  • [Index Lengths & MySQL / MariaDB](https://laravel.com/docs/9.x/migrations#index-lengths-mysql-mariadb) – steven7mwesigwa Nov 08 '22 at 04:59
  • That was what caused the string length to be 191. But i had the confusion of whats leads to it becoming 191, I never edited the app service provider file before. – ggcode Nov 08 '22 at 06:06
  • Also the foreign key is still not assigned, what could be the problem? – ggcode Nov 08 '22 at 06:08
  • Where is the migration of the `fieldequips` database table? – steven7mwesigwa Nov 08 '22 at 06:26
  • In addition, what Laravel framework version are you using? – steven7mwesigwa Nov 08 '22 at 06:36
  • ```fieldequips``` is another table. Im trying to set up a foreign key in ```calibrations``` that link to ```fieldequips``` – ggcode Nov 08 '22 at 09:04
  • Im using laravel 9.31.0 . Its really weird because i encounter this problem where certain code are still working but when i copy-paste it, it doesn't work anymore. Before this, i met a lot of problem deploying my project to domains so i ran a lot of command via the terminal. I wonder if thats the problem. – ggcode Nov 08 '22 at 09:06
  • I'm already aware that it belongs to another table. Could you kindly share it as well? – steven7mwesigwa Nov 08 '22 at 11:25

1 Answers1

0

In app/Providers/AppServiceProvider.php you should change Schema::defaultStringLength(191) to Schema::defaultStringLength(255), I guess

Andrey Bessonov
  • 338
  • 1
  • 7