title: Scala, play - cannot insert into Postgresql database
body: <p>I have a simple scala and play code for inserting product into database.</p>
  
  <p>My database config in application.conf looks like:</p>
  
  <pre><code>db.default.hikaricp.connectionTestQuery = "SELECT 1"
  
  db.default.driver=org.postgresql.Driver
  db.default.url="jdbc:postgresql://localhost:5432/shop"
  db.default.user="postgres"
  db.default.password="root"
  </code></pre>
  
  <p>Table definition and crud operations:</p>
  
  <pre><code>case class Product(id: Long, name: String, description: String, price: BigDecimal, amount: Int)
  
  case class ProductFormData(name: String, description: String, price: BigDecimal, amount: Int)
  
  object ProductForm {
  
    val form = Form(
      mapping(
        "name" -&gt; nonEmptyText,
        "description" -&gt; nonEmptyText,
        "price" -&gt; bigDecimal,
        "amount" -&gt; number
      )(ProductFormData.apply)(ProductFormData.unapply)
    )
  }
  
  class ProductTableDef(tag: Tag) extends Table[Product](tag, "product") {
  
    def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
  
    def name = column[String]("name")
  
    def description = column[String]("description")
  
    def price = column[BigDecimal]("price")
  
    def amount = column[Int]("amount")
  
    override def * =
      (id, name, description, price, amount) &lt;&gt; (Product.tupled, Product.unapply)
  }
  
  object Products {
  
    val products = TableQuery[ProductTableDef]
  
    private def db: Database = Database.forDataSource(DB.getDataSource())
  
    def add(product: Product): Future[Int] = {
      try db.run(products += product)
      finally db.close
    }
  
    def delete(id: Long): Future[Int] = {
      db.run(products.filter(_.id === id).delete)
    }
  
    def get(id: Long): Future[Option[Product]] = {
      db.run(products.filter(_.id === id).result.headOption)
    }
  
    def listAll: Future[Seq[Product]] = {
      db.run(products.result)
    }
  }
  </code></pre>
  
  <p>service:</p>
  
  <pre><code>object ProductService {
    def addProduct(product: Product): Future[Int] = {
      Products.add(product)
    }
  }
  </code></pre>
  
  <p>and controller:</p>
  
  <pre><code>def create() = Action(parse.json) { request =&gt;
      val name = (request.body \ "name").as[String]
      val description = (request.body \ "description").as[String]
      val price = (request.body \ "price").as[BigDecimal]
      val amount = (request.body \ "amount").as[Int]
  
      val product = Product(0, name, description, price, amount)
      ProductService.addProduct(product)
  
      Ok("name : " + product.name)
    }
  </code></pre>
  
  <p>Everything looks good, no errors in process (I use postman, creating json and send it to server). But after all there is no data in databse. Even table is not created in database. I really don't know why this cannot be add to database.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>create table "Product" ("id" BIGSERIAL NOT NULL PRIMARY KEY,"name" VARCHAR(254) NOT NULL,"description" VARCHAR(254) NOT NULL,"price" Decimal, "amount" BIGINT NOT NULL);
  </code></pre>
  
  <p>This is a script which I use to create table manually, then I try to save data frm request into database. From request everything is read fine (object Product is created) but no data still is safe into database.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <pre><code>case class Product(id: Option[Long], name: String, description: String, price: BigDecimal, amount: Int)
  
  class ProductTableDef(tag: Tag) extends Table[Product](tag, "product") {
  
    def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
  
    def name = column[String]("name")
  
    def description = column[String]("description")
  
    def price = column[BigDecimal]("price")
  
    def amount = column[Int]("amount")
  
    override def * =
      (id.?, name, description, price, amount) &lt;&gt; (Product.tupled, Product.unapply)
  }
  </code></pre>
  
  <p>I updated models and dao with Option auto increment field, but It didn't help.</p>