Cannot create tables with circular foreign key dependencies with SQLite
> SQLite doesn’t support the ALTER TABLE … ADD CONSTRAINT syntax (source), which is why there’s a syntax error here.

Good point. I think I will leave this out as anyone using SQLite probably should already be aware of the limited support for alter table. And circular FKs are a bad design!

TL;DR: SQLite doesn’t support the `ALTER TABLE … ADD CONSTRAINT` syntax used by `db.create_foreign_key`.

---

Hello,

I’m trying to store genealogical data in an SQLite database with the following simplified models:

``` python
FamilyProxy = Proxy()

class Person(Model):
    # the family where this person is a child in
    family = ForeignKeyField(FamilyProxy, related_name='children')

class Family(Model):
    father = ForeignKeyField(Person, related_name='father_in')
    mother = ForeignKeyField(Person, related_name='mother_in')

FamilyProxy.initialize(Family)
```

The [doc about circular dependencies](http://peewee.readthedocs.org/en/latest/peewee/models.html#circular-foreign-key-dependencies) mentions the `Proxy` workaround and at the end shows an example of what we need to do when creating tables, which gives this for my example:

``` py
db.create_tables([Person, Family], safe=True)
db.create_foreign_key(Person, Person.family)
```

And here lies the problem: the `create_foreign_key` method called here gives a syntax error with SQLite:

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mymodule/store.py", line 68, in create_tables
    db.create_foreign_key(Person, Person.family)
  File "/…/lib/python2.7/site-packages/peewee.py", line 2974, in create_foreign_key
    model_class, field, constraint))
  File "/…/lib/python2.7/site-packages/peewee.py", line 2877, in execute_sql
    self.commit()
  File "/…/lib/python2.7/site-packages/peewee.py", line 2732, in __exit__
    reraise(new_type, new_type(*exc_value.args), traceback)
  File "/…/lib/python2.7/site-packages/peewee.py", line 2869, in execute_sql
    cursor.execute(sql, params or ())
peewee.OperationalError: near "CONSTRAINT": syntax error
```

I added a `print` statement in the code to understand the syntax error:

``` sql
ALTER TABLE "person" ADD CONSTRAINT "fk_person_family_id_refs_family" FOREIGN KEY ("family_id") REFERENCES "family" ("id")
```

SQLite doesn’t support the `ALTER TABLE … ADD CONSTRAINT` syntax ([source](http://www.sqlite.org/omitted.html)), which is why there’s a syntax error here.

---

I can rewrite my code to avoid circular dependencies (with more complex queries), but you might want to add a notice in the documentation about this issue with SQLite.
