Issue: insert_many get error "KeyError('"%s" is not a recognized field.' % field)" while same data can be stored by mode.save
Author: cn-qlg
State: closed
Created: 2018-01-02 08:31:04

The original code like this:

```
detail = {'bookingCountStatus': 1, 'endTime': '2018-01-02 20:40:00', 'classid': '5584', 'startTime': '2018-01-02 19:40:00', 'tag': 'BBB', 'scheduleId': '40089221', 'boxId_id': 1024, 'supermonkeyCardPrice': 4275, 'scheduleDate': '2018-01-02', 'price': 4500, 'className': 'AAA'}

sch = ScheduleDetail.create(**detail)
sch.save()


sch_details = []
sch_details.append(detail)
if len(sch_details) > 0:
    with database.atomic():
        ScheduleDetail.insert_many(sch_details).execute()
database.close()
```
If I use Mode.create, and then call save(), it can work.
But, there are more than 1 records, so I need to use insert_many(), but KeyError was raised.
```
Traceback (most recent call last):
  File "C:\Users\aaa\Desktop\Work\Python\bbb.py", line 110, in <module>
    get_schedule_detail('40089221')
  File "C:\Users\aaa\Desktop\Work\Python\bbb.py", line 86, in get_schedule_detail
    ScheduleDetail.insert_many(sch_details).execute()
  File "C:\Users\aaa\AppData\Local\Programs\Python\Python35-32\lib\site-packages\peewee.py", line 3584, in execute
    cursor = self._execute()
  File "C:\Users\aaa\AppData\Local\Programs\Python\Python35-32\lib\site-packages\peewee.py", line 2938, in _execute
    sql, params = self.sql()
  File "C:\Users\aaa\AppData\Local\Programs\Python\Python35-32\lib\site-packages\peewee.py", line 3552, in sql
    return self.compiler().generate_insert(self)
  File "C:\Users\aaa\AppData\Local\Programs\Python\Python35-32\lib\site-packages\peewee.py", line 2103, in generate_insert
    for row_dict in query._iter_rows():
  File "C:\Users\aaa\AppData\Local\Programs\Python\Python35-32\lib\site-packages\peewee.py", line 3504, in _iter_rows
    validate_field(key)
  File "C:\Users\aaa\AppData\Local\Programs\Python\Python35-32\lib\site-packages\peewee.py", line 3494, in validate_field
    raise KeyError('"%s" is not a recognized field.' % field)
KeyError: '"boxId_id" is not a recognized field.'
[Finished in 1.5s with exit code 1]
```

Some more information about the Model definition.
```
class BoxInfo(BaseModel):
    """docstring for BoxInfo"""
    boxId = IntegerField(primary_key=True)
    boxname = CharField(null=True)
    city = CharField(null=True)
    address = CharField(null=True)


class ScheduleDetail(BaseModel):
    scheduleId = CharField(null=True)
    classid = CharField(null=True)
    boxId = ForeignKeyField(BoxInfo, to_field='boxId')
    endTime = CharField(null=True)
    startTime = CharField(null=True)
    bookingCountStatus = CharField(null=True)
    price = CharField(null=True)
    supermonkeyCardPrice = CharField(null=True)
    classIntroduce = CharField(null=True)
    suitablePeople = CharField(null=True)
    trainingEffect = CharField(null=True)
    className = CharField(null=True)
    tag = CharField(null=True)
```

I am not sure if it is a bug, or something else. And I try to debug it, I find insert_many() will call validate_field() method, while Model.create().save() not. So, I add a parameter to insert_many(), like this ```ScheduleDetail.insert_many(sch_details, validate_fields=True).execute()```. But another error is raised "KeyError: '"scheduleDate" is not a recognized field."

Env:
Windows 10 + python 3.5.2 + peewee 2.10.0

Correct:
ScheduleDetail.insert_many(sch_details, validate_fields=True).execute(). But another error is raised "KeyError: '"scheduleDate" is not a recognized field."

---
```ScheduleDetail.insert_many(sch_details, validate_fields=False).execute()```, when use validate_fields=False,  it said "AttributeError: 'str' object has no attribute '_sort_key'"

Use `boxId` instead of `boxId_id`. Also, did you happen to try this on Peewee 3.0a? Furthermore, `scheduleDate` is not a recognized field, so you should not include it in the `insert_many()` call.

I used boxId_id instead of boxId, it was because in the before, some errors were raised when created tables,  said that something wrong with boxId(The detail error message I forgot.), and then I found  in the table, the field changed to 'boxId_id', so I try to use boxId_id, and happen to work.
Anyway, thanks a lot.