Coder Social home page Coder Social logo

Comments (7)

staudenmeir avatar staudenmeir commented on July 1, 2024 1

/cc @hafezdivandari

from framework.

staudenmeir avatar staudenmeir commented on July 1, 2024

Hi @adiachenko,
Did you log and compare the Schema::create() queries between Laravel 10 and 11?

from framework.

adiachenko avatar adiachenko commented on July 1, 2024

I went through our migrations one by one and managed to distill some sort of example to replicate the issue.

Assume we have the following SQL schema dump file:

CREATE TABLE partners (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  support_priority INTEGER DEFAULT 0 NOT NULL,
);

Then we have the following 2 migrations to run on top of that file:

Schema::table('partners', function (Blueprint $table) {
    $table->unsignedSmallInteger('partner_type')->nullable();
});

Schema::table('partners', function (Blueprint $table) {
    $table->unsignedSmallInteger('partner_type')->default(0)->change();
});

When running the second alter table statement Laravel 11 will execute the following queries:

create table "__temp__partners" (
  "id" integer primary key autoincrement not null,
  "support_priority" integer not null,
  "partner_type" integer not null default '0'
);

drop table "partners";

alter table
  "__temp__partners" rename to "partners";

Note how support_priority is now just not null somehow without any default.

After I manually replaced default 0 with default '0' in schema dump it generated a correct query.

create table "__temp__partners" (
  "id" integer primary key autoincrement not null,
  "support_priority" integer not null default '0',
  "partner_type" integer not null default '0'
)

However, I do not like this "fix", because it will be overridden each time I recreate SQL dump meaning I will need to manually change all of these again.

from framework.

hafezdivandari avatar hafezdivandari commented on July 1, 2024

@staudenmeir thank you for mentioning me.

The issue seems to be on the following line, causes default 0 to be null:

'default' => $column['default'] ? new Expression($column['default']) : null,

I'm on vacation until Friday, and can't send a PR till then.

from framework.

github-actions avatar github-actions commented on July 1, 2024

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

from framework.

sinarahmany avatar sinarahmany commented on July 1, 2024

A possible workaround is to manually update the schema dump to use DEFAULT '0' instead of DEFAULT 0. However, this isn't ideal as it requires manual intervention each time the schema dump is recreated.

I suggest opening a pull request to address this issue in SQLiteGrammar.php.

from framework.

hafezdivandari avatar hafezdivandari commented on July 1, 2024

You may check PR #51803

from framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.