Code Monkey home page Code Monkey logo

tutorial2's Introduction

MyVendor.Ticket

Installation

composer install

Usage

Invoke Request

composer page get /

Available Commands

composer serve             // start builtin server
composer test              // run unit test
composer tests             // test and quality checks
composer coverage          // test coverage
composer cs-fix            // fix the coding standard
composer doc               // generate API document
composer run-script --list // list all commands

Links

tutorial2's People

Contributors

koriym avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

suzumaze

tutorial2's Issues

動作しない問題

  • PDOでエンティティが小文字に強制的に変換されてしまう => エンティティをコンストラクタインジェクションに
  • SELECTを検知できない => コメントを外す(一時的)
  • composer.jsonのdev/toolのバージョン => ^1.0に
  • composer.jsonのray/mediaqueryのバージョン => ^0に

ticketテーブル作成エラー

現象

ticket テーブルを作成するために composer setup を実行するとプライマリキーのNULL制約についてのエラーが発生します。

/workspaces/MyVendor.Ticket$ composer setup
> php bin/setup.php
Phinx by CakePHP - https://phinx.org.

using config file var/phinx/phinx.php
using config parser php
using migration paths 
 - /workspaces/MyVendor.Ticket/var/phinx/migrations
using environment development
using database ticket
ordering by creation time

 == 20221017052941 Ticket: migrating 
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1171 All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead in /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php:192
Stack trace:
#0 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php(192): PDO->exec('CREATE TABLE `t...')
#1 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/MysqlAdapter.php(357): Phinx\Db\Adapter\PdoAdapter->execute('CREATE TABLE `t...')
#2 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/AdapterWrapper.php(349): Phinx\Db\Adapter\MysqlAdapter->createTable(Object(Phinx\Db\Table\Table), Array, Array)
#3 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/TimedOutputAdapter.php(113): Phinx\Db\Adapter\AdapterWrapper->createTable(Object(Phinx\Db\Table\Table), Array, Array)
#4 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Db/Plan/Plan.php(146): Phinx\Db\Adapter\TimedOutputAdapter->createTable(Object(Phinx\Db\Table\Table), Array, Array)
#5 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Db/Table.php(716): Phinx\Db\Plan\Plan->execute(Object(Phinx\Db\Adapter\TimedOutputAdapter))
#6 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Db/Table.php(612): Phinx\Db\Table->executeActions(false)
#7 /workspaces/MyVendor.Ticket/var/phinx/migrations/20221017052941_ticket.php(25): Phinx\Db\Table->create()
#8 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Migration/Manager/Environment.php(108): Ticket->change()
#9 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php(388): Phinx\Migration\Manager\Environment->executeMigration(Object(Ticket), 'up', false)
#10 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php(359): Phinx\Migration\Manager->executeMigration('development', Object(Ticket), 'up', false)
#11 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Console/Command/Migrate.php(122): Phinx\Migration\Manager->migrate('development', 20221017052941, false)
#12 /workspaces/MyVendor.Ticket/vendor/symfony/console/Command/Command.php(291): Phinx\Console\Command\Migrate->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /workspaces/MyVendor.Ticket/vendor/symfony/console/Application.php(1002): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /workspaces/MyVendor.Ticket/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand(Object(Phinx\Console\Command\Migrate), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/src/Phinx/Console/PhinxApplication.php(70): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /workspaces/MyVendor.Ticket/vendor/symfony/console/Application.php(171): Phinx\Console\PhinxApplication->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /workspaces/MyVendor.Ticket/vendor/robmorgan/phinx/bin/phinx(28): Symfony\Component\Console\Application->run()
#18 /workspaces/MyVendor.Ticket/vendor/bin/phinx(120): include('/workspaces/MyV...')
#19 {main}
Phinx by CakePHP - https://phinx.org.

環境

  • PHP 8.0.12 (Docker container PHP:8-alpine)
  • MySQL 8.0.31 (Docker container mysql:8-debian)

実行SQLの調査

どんなSQL文が実行されているか調べるため vendor/robmorgan/phix/src/Db/Adapter/PdoAdapter.php の192行目にechoを入れました。

    public function execute(string $sql, array $params = []): int
    {
        $sql = rtrim($sql, "; \t\n\r\0\x0B") . ';';
        $this->verboseLog($sql);

        if ($this->isDryRunEnabled()) {
            return 0;
        }

        if (empty($params)) {
+           echo PHP_EOL . 'SQL => ' . $sql . PHP_EOL;
            return $this->getConnection()->exec($sql);
        }

        $stmt = $this->getConnection()->prepare($sql);
        $result = $stmt->execute($params);

        return $result ? $stmt->rowCount() : $result;
    }

composer setup を実行すると次のように表示されました。

SQL => CREATE TABLE `ticket` (`id` CHAR(36) NULL, `title` VARCHAR(255) NULL, `date_created` DATETIME NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

id 列が NULL 許可になっています。

これはMySQL 5.7.3で修正された「プライマリキーはNOT NULLでなければならない」という仕様に違反しています。

https://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-3.html#mysqld-5-7-3-bug

Columns in a PRIMARY KEY must be NOT NULL, but if declared explicitly as NULL produced no error. Now an error occurs. For example, a statement such as CREATE TABLE t (i INT NULL PRIMARY KEY) is rejected.

(とはいえ MySQL 5.7.3 は2013年なので、今ごろ急に影響が出るとは考えにくいです)

とりあえず動作させる方法

マイグレーションファイル var/phinx/migrations/XXXX_ticket.phpid 列に 'null' => false オプションを付けることでエラーが出なくなりテーブルが作成されました。

    public function change()
    {
        $table = $this->table('ticket', ['id' => false, 'primary_key' => ['id']]);
-       $table->addColumn('id', 'uuid')
+       $table->addColumn('id', 'uuid', ['null' => false])
            ->addColumn('title', 'string')
            ->addColumn('date_created', 'datetime')
            ->create();
    }

とはいえ、これが正解かわかりません。

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.