Sails: Autoincrement attribute invalid in standalone waterline

Created on 24 Apr 2018  路  7Comments  路  Source: balderdashy/sails

Waterline version:0.13.3
Node version: 5.8.0
NPM version:9.11.1
Operating system: Zen Arch Linux



I am trying to create an autoincrement property in my waterline model definition. when i do and i run my server i get into this error The attribute ``id`` on the ``ownershipchangeaction`` model contains invalid properties. The property ``autoIncrement`` isn't a recognized property. where ownershipchangeaction is my model's name.
I am using the sails-mysql adapter. How can i make an automatically incremented column in waterline ? am i missing something ?
here is my model :

var OwnerShipChangeAction = Waterline.Collection.extend({
  identity: 'ownershipchangeaction',
  datastore: 'default',
  primaryKey: 'id',
  attributes: {
    id: {type:'number',autoIncrement:true},
    cert: {type:'string'},
    iss : {type:'string'},
    fiss :{type:'string'},
    owner :{type:'string'},
    createdAt: { type: 'number', autoCreatedAt: true, },
    updatedAt: { type: 'number', autoUpdatedAt: true, },
  }

});

i get this when i remove the autoincrement property :
Error: In model ``ownershipchangeaction``, primary key ``id`` must have either ``required`` or ``autoIncrement`` set.

orm question resolved standalone waterline

Most helpful comment

@cdeveas Yes and I am seeing a lot of miss-documentations .
I did solve this by using it this way : autoMigrations:{autoIncrement:true}
and I am having problems with setting the ColumnType too.
The official documentation is way OLD and not regularly updated, especially for Standalone waterline.

All 7 comments

Hi @moda20! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:

  • Verify "I am experiencing a concrete technical issue with Waterline (ideas and feature proposals should follow the guide for proposing features and enhancements (http://bit.ly/sails-feature-guide), which involves making a pull request). If you're not 100% certain whether it's a bug or not, that's okay--you may continue. The worst that can happen is that the issue will be closed and we'll point you in the right direction."
  • Verify "I am not asking a question about how to use Waterline or about whether or not Waterline has a certain feature (please refer to the documentation(http://sailsjs.org), or post on http://stackoverflow.com, our Google Group (http://bit.ly/sails-google-group) or our live chat (https://gitter.im/balderdashy/sails)."
  • Verify "I have already searched for related issues, and found none open (if you found a related _closed_ issue, please link to it in your post)."

As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]

Seeing this as well.

@cdeveas Yes and I am seeing a lot of miss-documentations .
I did solve this by using it this way : autoMigrations:{autoIncrement:true}
and I am having problems with setting the ColumnType too.
The official documentation is way OLD and not regularly updated, especially for Standalone waterline.

@moda20 I did like a lot of features of Waterline, but the latest version seems to depend heavily on Sails (understandably). I ended up going with TypeORM for my small project. There's an ES6 non-typescript example implementation here: https://github.com/typeorm/javascript-example

_Apologies for mentioning another ORM within a waterline Issue_

@moda20 @chasdevs looks like you got it under control with the autoMigrations. For reference to others viewing this issue, documentation here:
https://sailsjs.com/documentation/concepts/models-and-orm/standalone-waterline-usage
@moda20 feel free to update the issue with a specific question re: columnType. Did you take a look at this yet? https://sailsjs.com/documentation/concepts/models-and-orm/attributes#columntype

@oaksofmamre @chasdevs @moda20 - Hey everyone, we're currently in the process of moving all the Waterline cases to Sails (balderdashy/sails) for greater exposure. We appreciate all the effort put into solving this one and welcome any further updates or related feedback. Thanks.

@pranay-sonisoft @calvin-evans @moda20 Hey y'all just to wrap this up, and for anyone finding this issue in the future, here are the takeaways:

  • As of Sails v1, sails-hook-orm does automigrations. If you're Waterline standalone (outside of a Sails app), it's up to you to migrate your data during development.
  • As @oaksofmamre mentioned, you could put this setting under autoMigrations, but that won't do anything outside of the context of Sails. If you're doing something very custom and want to use automigrations on their own, it's technically possible (see the waterline-utils package), though I wouldn't recommend it because it's unconventional.

Thanks everyone for the help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mahfuzur picture mahfuzur  路  3Comments

kesavkolla picture kesavkolla  路  4Comments

alxndrsn picture alxndrsn  路  4Comments

radoslavpetranov picture radoslavpetranov  路  4Comments

victory-deployment picture victory-deployment  路  4Comments