Welcome Guest, Not a member yet? Register   Sign In
CI4 Mysql DB Forge Error with INT default value negitive.
#1
Question 

Hi,
I've run into a odd bug I think. I'm setting up a new CI4.3.1 and Mysql 8 project. In the migration I have a int field that has a default value that is a negative value. I thought it might be like using CURRENT_TIMESTAMP in a DATETIME or TIMESTAMP field and I would need to encase in RawSql(). As the table didn't get generated when it ran.

It didn't help i changed the value positive and it work.So I made this command to test to see if it was negative values.
PHP Code:
use CodeIgniter\CLI\BaseCommand;
use 
CodeIgniter\CLI\CLI;
use 
CodeIgniter\Database\RawSql;

class 
TestIntForge extends BaseCommand
{

    protected $group 'Test';
    protected $name 'test:forgeint';
    protected $description '';
    protected $usage 'test:forgeint';

    public function run(array $params)
    {
        $forge = \Config\Database::forge('test_');
        for ($i=3;$i>-5;--$i) {
            CLI::write("Testing ".$i.': ');

            $forge->addField([
                'id' => ['type' => 'BIGINT''constraint' => '20' 'unsigned' => true 'auto_increment' => true 'null' => false ],
                'test_int' => ['type' => 'INT''constraint' => '11' 'unsigned' => true 'null' => false'default' => new RawSql($i) ], 
            ]);

            $forge->addKey('id'true);
            if ($forge->createTable('test_'.$itrue)) {
                $forge->dropTable('test_'.$i);
                CLI::write(CLI::color('PASS''green'));
            }
            else {
                CLI::write(CLI::color('FAILED''red'));
            }
        }
    }


When I ran it this was the output.
Testing 3: PASS
Testing 2: PASS
Testing 1: PASS
Testing 0: PASS
Testing -1: FAILED
Testing -2: FAILED
Testing -3: FAILED
Testing -4: FAILED


I figured I would ask before digging into the system code, hoping it it's just something simple I've overlooked.
Reply
#2

You set `unsigned`.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB