question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't add a new batch because columns: don't have default values. DB defaults don't support in batch inserts

See original GitHub issue

Hello,

when I try to insert something in a many to many table with an extra column, it just throws the exception above. I am using MySQL.

My tables look like this:

object ManyToManys : UUIDTable("many_to_manys") {
    val table1 = reference("table1", Tables1)
    val table2 = reference("table2", Tables2)
    val position = integer("position")

    override val primaryKey = PrimaryKey(table1, position)
}

class ManyToMany(id: EntityID<UUID>) : UUIDEntity(id) {
    companion object : EntityClass<UUID, ManyToMany>(ManyToManys)

    var table1 by Table1 referencedOn ManyToManys.table1
    var table2 by Table2 referencedOn ManyToManys.table2
    var position by ManyToManys.position
}

(I am using this disgusting UUID hack since Exposed does not support many to many tables with extra columns)

when I try to insert via

ManyToMany.new {
    this.table1 = myTable1
    this.table2 = myTable2
    this.position = myPos
}

it crashes with org.jetbrains.exposed.sql.statements.BatchDataInconsistentException: Can't add a new batch because columns: many_to_manys.`position` don't have default values. DB defaults don't support in batch inserts eventhough I have supplied a position.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
maffelbaffelcommented, Jan 19, 2021

Had the same Problem because a column was not specified as nullable e.g. description

object Projects : UUIDTable() {
    val title = varchar("title", 32)
    val description = varchar("description", 255)
}
class Project(id: EntityID<UUID>) : UUIDEntity(id) {
    companion object : UUIDEntityClass<Project>(Projects)

    var title by Projects.title
    var description by Projects.description
}

Added a project using Project.new in my service without setting a value for description:

transaction {
        Project.new {
            title = model.title
        }
}

Changed description to nullable with val description = varchar("description", 255).nullable(). That resolved my problem.

0reactions
Tapaccommented, Nov 18, 2020

@gringofe , @stalexxx , please share a reproducible sample project on GitHub and I’ll debug it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kotlin Exposed batch insert not working as documented
I am trying to batch insert records into an SQL table using Kotlin Exposed. I have set up the code as per the...
Read more >
Keep nulls or default values during bulk import - SQL Server
* For BULK INSERT, if default values are not available, the table column must be defined to allow null values.
Read more >
Table updates not working with default values when used in ...
Hi, first post here so be gentle! I've had an issue where we use Oracle to update a bunch of records using batch...
Read more >
Problems with adding NOT NULL columns or making nullable ...
This can happen when you try to add a new column that can't accept NULL values, or to change an existing, nullable column...
Read more >
How to add a column with a default value to an existing table ...
How to: To SQL add a column with a default value is a simple operation in SQL. ... INSERT INTO student(student_id, student_name, major,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found