yiisoft / yiisoft/db-migration

The migrator modifies native SQL

Open
#336 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
32
Forks
18
Avg merge
22h 18m
Merged PRs (30d)
2

Description

Description

Let's look at a snippet from my migration:

$b->createTable(..., [
       <...>
            'owner_user_id' => 'bigint REFERENCES users(id) ON DELETE SET NULL', <...>
        ]);

For some reason, I get the following error:

SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near ","     
  LINE 9: ...ner_user_id" bigint NULL REFERENCES users(id) ON DELETE SET, 

But if we look closely at the resulting script, or rather, a portion of it, for some unknown reason, the part with NULL has simply disappeared, resulting in a dangling SET:

  The SQL being executed was: CREATE TABLE <...>                                                                         
        "owner_user_id" bigint NULL REFERENCES users(id) ON DELETE SET,                         
        "uploaded_at" <...>
  )   
Package version

2.0.1

PHP version

8.4.18

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the migration snippet and generated CREATE TABLE SQL; trace the migrator's column-definition handling for REFERENCES and ON DELETE clauses, then reproduce the reported syntax error. Done means the generated SQL preserves ON DELETE SET NULL and the migration no longer produces the shown malformed statement.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sql
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.