mysql: not null / required column #110

Closed
GoNode5 opened this Issue Apr 10, 2013 · 6 comments

Projects

None yet

3 participants

@GoNode5
GoNode5 commented Apr 10, 2013

How to define an required column in a model. In Mysql I define a column with

CREATE TABLE test (
testcol varchar(45) NOT NULL,

Not sure how to define this in Orm2

@dresende
Owner

There isn't yet, I'll work on it.

@dresende
Owner

Get the latest git version and try this (adjust to your code):

orm.settings.set("properties.not_null", true); // changes default to NOT NULL

orm.connect("mysql://....", function (err, db) {
    var Person = db.define('person', {
        name : String
    });
    Person.sync();

    // ...
});
@GoNode5
GoNode5 commented Apr 10, 2013

ok your very fast. Thanks for all your help.... The next problem is existing tables... how to add null? And what about validation... it would be great if this was also default handled (you cant create an item anyway...)

@dresende
Owner

Existing tables are more hard to handle but it's in the plans (#103). For validations look at the first example in the Readme. I know the documentation is scarse but I tend to code more and document less.

@dxg
Collaborator
dxg commented Apr 10, 2013

Probably just nitpicking, but could we call this setting 'required' just like we have on has one associations? It does the same thing. I'm also thinking that 'notnull' may not make sense for non-sql datastores. 'required' is more general.

@dresende
Owner

Agree

@dresende dresende closed this Apr 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment