Sails: Transforming columnNames back to attribute names

Created on 17 May 2017  路  9Comments  路  Source: balderdashy/sails

Waterline version: 0.13.0-rc9
Node version: v7.9.0
NPM version: 4.2.0
Operating system: Windows 10 pro



Warning: After transforming columnNames back to attribute names, a record
in the result has a value with an unexpected data type for property created.
The corresponding attribute declares type: 'string' but instead
of that, the actual value is:

2017-05-17T11:08:24.000Z

You are seeing this warning because there are records in your database that don't
match up with your models. This is often the result of a model definition being
changed without also migrating leftover data. But it could also be because records
were added or modified in your database from somewhere outside of Sails/Waterline
(e.g. phpmyadmin, or another app). In either case, to make this warning go away,
you have a few options. First of all, you could change your model definition so
that it matches the existing records in your database. Or you could update/destroy
the old records in your database; either by hand, or using a migration script.

(For example, to wipe all data, you might just use migrate: drop.)

More rarely, this warning could mean there is a bug in the adapter itself. If you
believe that is the case, then please contact the maintainer of this adapter by opening
an issue, or visit http://sailsjs.com/support for help.

Here is my model:

module.exports = { attributes: { someDate: { type: 'string', columnType: 'datetime' } } };

Most helpful comment

Is there any way to turn off these warnings?

All 9 comments

@Alessy Thanks for posting, we'll take a look as soon as possible.


For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here.

Hey @Alessy, the attribute 'datetime' does not exist anymore on Sails 1.0
You should use the type: 'number' + columnType: 'bigint' to store an unix timestamp (same as createdAt and updatedAt fields)

However, if you are using sails-postgresql, there is a known issue here https://github.com/balderdashy/waterline/issues/1487 that you should take into account.

Best,

Hey @billyshena, I have the same issue with default model attributes for createdAt and updatedAt though I have been following your upgrade guide: https://github.com/balderdashy/sails-docs/blob/1.0/upgrading/To1.0.md#the-autoupdatedat-and-autocreatedat-model-settings-are-now-attribute-level-properties

As I have been using Sails since version 0.9 I cannot change all my database table from datetime to int.

attributes: {
    createdAt: { type: 'string', autoCreatedAt: true },
    updatedAt: { type: 'string', autoUpdatedAt: true },
   ...
}
Warning: After transforming columnNames back to attribute names, a record
in the result has a value with an unexpected data type for property `updatedAt`.
The model's `updatedAt` attribute declares itself an auto timestamp with
`type: 'string'`, but instead of a valid timestamp, the actual value
in the record is:
2017-05-26T12:42:46.000Z

What would you recommend to do?

@markBerlin

  • For type: 'string', these timestamps are stored in the same way as they were in Sails 0.12: as timezone-agnostic ISO 8601 JSON timestamp strings (e.g. '2017-12-30T12:51:10Z'). So if any of your front-end code is relying on the timestamps as strings it's important to set this to string.
  • For type: 'number', these timestamps are stored as JS timestamps (the number of milliseconds since Jan 1, 1970 at midnight UTC).

To move to v1.0 you need a migration to pull in all your datetimes, convert them to ISO 8601 timestamp strings with momentjs or whatever your preferred formatting tool is. I'd create an object cache associate row id to timestamp, then execute an alter table that drops the column, then add the column again but with the new datatype, then insert. Then your model can still be string.

You should look into if your database adapter exposes a migration cli tool like this one for sequelize.

Or you shouldn't upgrade to v1.0,

@Alessy,@sailsbot,@billyshena,@markBerlin,@snewell92: Hello, I'm a repo bot-- nice to meet you!

It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message and simply close the issue if possible. On the other hand, if you are still waiting on a patch, please post a comment to keep the thread alive (with any new information you can provide).

If no further activity occurs on this thread within the next 3 days, the issue will automatically be closed.

Thanks so much for your help!

Is there any way to turn off these warnings?

Is there any way to turn off these warnings?

How to turn off these notifications in prod, while keeping them in staging / develop?

This is still a major issue.

Our prod logging is horrendous, 99% is just pointless warnings about our models.

For example for empty collections we return in native sql query an empty array and sails will display 50 lines long message about that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pawankorotane picture pawankorotane  路  3Comments

Alirezamohammadi picture Alirezamohammadi  路  4Comments

Sytten picture Sytten  路  4Comments

alxndrsn picture alxndrsn  路  4Comments

svmn picture svmn  路  4Comments