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

mysql: not null / required column #110

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

mysql: not null / required column #110

GoNode5 opened this issue Apr 10, 2013 · 6 comments

Comments

@GoNode5
Copy link

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
Copy link
Owner

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

@dresende
Copy link
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
Copy link
Author

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
Copy link
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
Copy link
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
Copy link
Owner

Agree

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

No branches or pull requests

3 participants