Skip to content

mysql: not null / required column #110

Closed

Description

@GoNode5

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

Activity

  1. dresende commented on Apr 10, 2013

    @dresende
    Owner

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

  2. dresende commented on Apr 10, 2013

    @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();
    
        // ...
    });
  3. GoNode5 commented on Apr 10, 2013

    @GoNode5
    Author

    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...)

  4. dresende commented on Apr 10, 2013

    @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.

  5. dxg commented on Apr 10, 2013

    @dxg
    Collaborator

    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.

  6. dresende commented on Apr 11, 2013

    @dresende
    Owner

    Agree

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions