Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building the MySQL database: Int fields are not allowed to have a default value #12

Open
Taitava opened this issue May 10, 2017 · 3 comments

Comments

@Taitava
Copy link
Contributor

Taitava commented May 10, 2017

This is just a quick post about an SQL error I just encountered when trying to run /dev/build.

[User Error] Uncaught SS_DatabaseException: Couldn't run query: ALTER TABLE "EncryptionTestObject" ADD "IntEnc" mediumtext character set utf8 collate utf8_general_ci default '0' 42000-1101: BLOB, TEXT, GEOMETRY or JSON column 'IntEnc' can't have a default value

My PHP code:

class EncryptionTestObject extends DataObject
{
	private static $db = array(
		'IntEnc' => 'EncryptedInt',
	);
}

Got it working when I made a small change to the array in the EncryptedInt::requireField() method:

public function requireField()
    {
        $values = array(
            'type'  => 'text',
            'parts' => array(
                'datatype'   => 'text',
//                'precision'  => $this->service->calculateRequiredFieldSize(strlen('Y-m-d H:i:s')),
                'null'       => 'not null',
                'default'    => $this->defaultVal /* CHANGE THIS TO NULL */,
                'arrayValue' => $this->arrayValue
            )
        );

        DB::require_field($this->tableName, $this->name, $values);
    }

Should I create a pull request about this?

@Firesphere
Copy link
Collaborator

Yes please, sorry for the delayed reply. The precision for EncryptedInt shouldn't be needed anyway.

@Taitava
Copy link
Contributor Author

Taitava commented Aug 2, 2017

No problem :). I'll create a PR about this at some point :).

@Taitava
Copy link
Contributor Author

Taitava commented Aug 25, 2021

I just noticed some activity on this module and saw this old issue of mine. Well, it appears that the "PR at some point" newer happened, sorry :).

As I'm not anymore working on a project where I used this module, I think I'll just drop this out of my todo list :). If anyone else needs a fix for this, they are free to create a pull request, this seems to be a quite easy thing, just needs testing that it works because it's been many years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants