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

Data type "boolean" is not supported in "mysql" database. #642

Closed
jounii opened this issue Jul 10, 2017 · 10 comments
Closed

Data type "boolean" is not supported in "mysql" database. #642

jounii opened this issue Jul 10, 2017 · 10 comments
Labels

Comments

@jounii
Copy link

jounii commented Jul 10, 2017

typeorm 0.1.0-alpha.28 is giving now error Data type "boolean" is not supported in "mysql" database. if using boolean datatype. Running with sqlite this works fine.

This used to work with 0.0.11. I suppose I could fallback to tinyint as solution for now.

@hugoserrana
Copy link

@jounii The MySql does not have internal BOOLEAN data type. Types like BOOLEAN and BOOL are TINYINT(1) internally.

In Changelog the TypeOrm team wrote this:

some column types were removed. Now orm uses directly column types of underlying database

I think they made the right decision because the types are mapped explicitly. I imagine this will reduce errors in maintaining this awesome library.

@pleerock
Copy link
Member

@jounii if you define column type explicitly then you must use tinyint because explicitly defined types are now only database-supported types as @hugoserrana said.

But if you variable is boolean you can simply omit type definition and it will be converted to tinyint automatically, e.g. for @Column() enabled: boolean you don't need to specify type - its automatically mapped to tinyint.

@jounii
Copy link
Author

jounii commented Jul 10, 2017

Mysql does have alias for BOOLEAN and BOOL to mapped to TINYINT. If you logic is right, shouldn't the sqlite implementation driver also rule tinyint and others out too? Sqlite uses internally only "integer" type and aliases rest.

Have to try if the boolean entity member is properly mapped if I don't specify the types manually.

@jounii
Copy link
Author

jounii commented Jul 12, 2017

Works ok without defining the type. Problem solved for now, thanks.

Related to this is if the tinyint (and others specific data size types) go out of fashion, the Column options would need some sort of data length/type hinting options so the driver could choose best suiting internal type.

Maybe possibility to define data type converter class/function so you could customise these yourself. I suppose I could override the DriverFactory to provide own wrapper driver, but it'll be exercise for later.

@feather-jmalone
Copy link
Contributor

maybe i'm missing something, but in 0.1.0-alpha.34 and 0.1.0-alpha.35, i'm unable to work around the issue as recommended. i tried the following in my entity definition:

@Column({ nullable: false, default: false }) someFlag: boolean;

and also

@Column() someFlag: boolean;

both result in the following exception: TypeORM connection error: { DataTypeNotSupportedError: Data type "" is not supported in "mysql" database.

did something change?

i can't get the column working unless i specify 'tinyint' as the first parameter for @Column. consequently, values come back as 1 or 0 instead of true or false.

@pleerock
Copy link
Member

Looks like it cannot figure out parameter type. Parameter type is automatically determined only if you setup reflect-metadata properly and setup tsconfig properly. Read more about them on a homepage

@feather-jmalone
Copy link
Contributor

ah, you're right. i did not have reflect-metadata. however, when i added import "reflect-metadata" to my main app.ts file as the docs suggested, i still got the error. adding the same line to the entity .ts file is what ultimately fixed the issue.

thanks for the help!

@pleerock
Copy link
Member

reflect-metadata should be loaded before any your entity is loaded. Probably you have loaded entities before your imported reflect-metadata in your app.ts

@feather-jmalone
Copy link
Contributor

i don't think so, but i am still new to TypeScript and TypeORM. here's an abbreviated version of my app.ts (took out Express-related code in the createConnection callback), does anything seem strange to you?

import {createConnection} from 'typeorm';
import "reflect-metadata";

// Establish the database connection before doing anything else
createConnection({
    type: 'mysql',
    host: process.env.DB_HOST,
    port: process.env.DB_PORT,
    username: process.env.DB_USER,
    password: process.env.DB_PASS,
    database: process.env.DB_NAME,
    entities: [
        __dirname + '/entity/*.js'
    ],
    autoSchemaSync: true
}).then(connection => {

    // Initialize Express and other things

// Log database connection errors
}).catch(error => 
{
    console.log('TypeORM connection error: ', error)
});

thanks again for your help. although my particular issue is solved, i wanna help with future documentation if this is in fact a scenario that's unaccounted for.

@pleerock
Copy link
Member

its not an unaccounted scenario, Im sure its something on your side. You can create a demo git repo with problem reproduction and I'll take why its happening on you

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

No branches or pull requests

4 participants