Skip to content

Instantly share code, notes, and snippets.

@elchappo
Forked from chrisguitarguy/dbal-nullable.php
Created May 2, 2016 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elchappo/8db7fb44270da911610e2e1430685014 to your computer and use it in GitHub Desktop.
Save elchappo/8db7fb44270da911610e2e1430685014 to your computer and use it in GitHub Desktop.
Just in case anyone was wondering how set allow a column to be nullable with Doctrine DBAL's Schema later.
<?php
use Doctrine\DBAL\Schema\Schema;
// assuming you're using composer...
$loader = require __DIR__ . '/vendor/autoload.php';
$schema = new Schema();
$users = $schema->createTable('users');
// doctrine calls methods of Doctrine\DBAL\Column based on options, the third argument of addColumn
// Eg. if you add a length. Doctrine does something like this.
// $col = new \Doctrine\DBAL\Column('colname')
// $col->setLength(255);
// Doctrine\DBAL\Column::setNotNull(bool $notnull) is the method call you want to make
// so just include notnull in your options! True will make the column NOT NULL, false will make it nullable.
$users->addColumn('reset_token', 'string', array('length' => 255, 'default' => null, 'notnull' => false));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment