phalcon / phalcon-devtools

Phalcon Developer Tools
https://docs.phalcon.io/latest/en/devtools
Other
1.33k stars 630 forks source link

Default value as '' #1465

Closed olegatro closed 4 years ago

olegatro commented 4 years ago

Questions should go to https://forum.phalconphp.com Documentation issues should go to https://github.com/phalcon/docs/issues

Expected and Actual Behavior

Describe what you are trying to achieve and what goes wrong.

Provide output if related

// paste output here

Provide minimal script to reproduce the issue

<?php

use Phalcon\Db\Column;
use Phalcon\Db\Index;
use Phalcon\Db\Reference;
use Phalcon\Mvc\Model\Migration;

/**
 * Class MenusMigration_350
 */
class MenusMigration_350 extends Migration
{
    /**
     * Define the table structure
     *
     * @return void
     */
    public function morph()
    {
        $this->morphTable('menus', [
                'columns' => [
                    new Column(
                        'id',
                        [
                            'type' => Column::TYPE_INTEGER,
                            'notNull' => true,
                            'autoIncrement' => true,
                            'size' => 11,
                            'first' => true
                        ]
                    ),
                    new Column(
                        'title',
                        [
                            'type' => Column::TYPE_CHAR,
                            'notNull' => true,
                            'size' => 255,
                            'after' => 'id'
                        ]
                    ),
                    new Column(
                        'lang',
                        [
                            'type' => Column::TYPE_CHAR,
                            'notNull' => true,
                            'size' => 3,
                            'after' => 'title'
                        ]
                    ),
                    new Column(
                        'url',
                        [
                            'type' => Column::TYPE_CHAR,
                            'default' => "",
                            'notNull' => true,
                            'size' => 255,
                            'after' => 'lang'
                        ]
                    ),
                    new Column(
                        'status',
                        [
                            'type' => Column::TYPE_BOOLEAN,
                            'default' => "1",
                            'notNull' => true,
                            'size' => 1,
                            'after' => 'url'
                        ]
                    ),
                    new Column(
                        'external',
                        [
                            'type' => Column::TYPE_BOOLEAN,
                            'default' => "0",
                            'notNull' => true,
                            'size' => 1,
                            'after' => 'status'
                        ]
                    )
                ],
                'indexes' => [
                    new Index('PRIMARY', ['id'], 'PRIMARY')
                ],
                'options' => [
                    'TABLE_TYPE' => 'BASE TABLE',
                    'AUTO_INCREMENT' => '',
                    'ENGINE' => 'InnoDB',
                    'TABLE_COLLATION' => 'utf8_general_ci'
                ],
            ]
        );
    }

    /**
     * Run the migrations
     *
     * @return void
     */
    public function up()
    {

    }

    /**
     * Reverse the migrations
     *
     * @return void
     */
    public function down()
    {

    }

}

Details

Hello in the 3v version. I have a problem - in some situation if I change field from requiement - to the field with defaul value '' - empty string, the migration doesn`t work.

In the code above the only line was added is - ``'default' => "", (in the url field)

sergeyklay commented 4 years ago

@Jeckerson Could you please take a look

Jeckerson commented 4 years ago

@sergeyklay It has been fixed in v2 of migrations.

olegatro commented 4 years ago

Thank you guys. I will close issue