Issue: Syntax Error whilst inserting model where model has only primary key or ManyToManyField column
Author: MrJohz
State: closed
Created: 2015-07-15 22:02:38

Test script: https://gist.github.com/MrJohz/863042d7d9abb80a35f9

``` console
$ python --version
Python 3.4.3
$ pip freeze
peewee==2.6.3
$ python test.py
(F) FailureModel instantiation failed: OperationalError('near ""failuremodel"": syntax error',)
(F) ManyToManyFailureModel instantiation (via create) failed: OperationalError('near ""manytomanyfailuremodel"": syntax error',)
(F) ManyToManyFailureModel instantiation (via __init__) failed: OperationalError('near ""manytomanyfailuremodel"": syntax error',)
(F) ManyToManyFailureModel instantiation (via insert) failed: OperationalError('near ""manytomanyfailuremodel"": syntax error',)
(S) SuccessfulModel instantiation succeeded
```

I have a model that only contains a single ManyToManyField.  I want to create a row, insert it into the table, and start adding links using the `ManyToManyField.add()` method, but I keep on getting an OperationalError syntax error.  Is this a bug, or am I doing something very bad and wrong?


What benefit do you get from having a model that only many-to-many's to another model?


Not to say your issue isn't valid, but just curious as it seems strange.


Well, testing with SQLite, I'm not sure that there's a way to actually `INSERT` "nothing" into a table that has only an auto-incrementing primary key.

Here's what Peewee is trying:

``` sql
INSERT INTO "failuremodel"
```

But it also fails if I try:

``` sql
INSERT INTO "failuremodel" ()
```

I think that you might be out of luck on this one.


It does seem a bit weird, but (apart from the syntax errors...) it works quite well - there are a bunch of values stored, and each request to a certain endpoint needs to be stored and connected to those values.  Normally I'd just make each value a column, but I'm trying to set the system up so that more values can be added at a later date without having to migrate the database.

According to the sqlite docs (https://www.sqlite.org/lang_insert.html), the third form of insert allows you to just write "DEFAULT VALUES" instead of specifying them.  (According to Google, SQL Server also has the same issue and solution).  I don't think this is necessary for mysql or pgsql, although I didn't really look to much into it.  Is it possible for peewee to do that?

Thanks for replying so quickly!


Having looked a bit further, sqlite and postgreSQL both allow the "DEFAULT VALUES" syntax, which replaces the "VALUES (expr*)" part of an insert query ([sqlite](https://www.sqlite.org/lang_insert.html), [pg](http://www.postgresql.org/docs/8.2/static/sql-insert.html)).  MySQL doesn't allow this, but does allow the "expr" part to be replaced by the keyword "DEFAULT" ([mysql](http://dev.mysql.com/doc/refman/5.6/en/insert.html)), which does essentially the same thing assuming you know how many columns there are.

I guess the question is whether the default row case (regardless of the number of columns) is a special enough case for peewee to treat it separately and call out to the default value syntaxes for the different DBs.  What do you reckon?


Thanks for looking into this, I'll see about updating peewee accordingly.


Thanks!