Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endlessly trying to do ADD CONSTRAINT and FOREIGN KEY #60

Open
zhekabourne opened this issue Sep 10, 2021 · 1 comment
Open

Endlessly trying to do ADD CONSTRAINT and FOREIGN KEY #60

zhekabourne opened this issue Sep 10, 2021 · 1 comment

Comments

@zhekabourne
Copy link

zhekabourne commented Sep 10, 2021

models.py:

from peewee import *
import peeweedbevolve
db = MySQLDatabase('test', user='root', password='', host='127.0.0.1', port=3307)

class Art(Model):
    name = CharField()

    class Meta:
        database = db
        table_name = 'arts'


class User(Model):
    class Meta:
        database = db
        table_name = 'users'

    name = CharField()
    art = ForeignKeyField(Art)


if __name__ == '__main__':
    db.evolve()

First launch
console:

Making updates to database: family_bot

Your database needs the following changes:

  CREATE TABLE IF NOT EXISTS `arts` (`id` INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` VARCHAR(255) NOT NULL); 
  CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` VARCHAR(255) NOT NULL, `art_id` INTEGER NOT NULL); 
  ALTER TABLE `users` ADD CONSTRAINT `fk_users_art_id_refs_arts` FOREIGN KEY (`art_id`) REFERENCES `arts` (`id`); 
  CREATE INDEX `user_art_id` ON `users` (`art_id`); 

Do you want to run these commands? (yes or no) yes
Running in 3... 2... 1... 

 CREATE TABLE IF NOT EXISTS `arts` (`id` INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` VARCHAR(255) NOT NULL); 
 CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` VARCHAR(255) NOT NULL, `art_id` INTEGER NOT NULL); 
 ALTER TABLE `users` ADD CONSTRAINT `fk_users_art_id_refs_arts` FOREIGN KEY (`art_id`) REFERENCES `arts` (`id`); 
 CREATE INDEX `user_art_id` ON `users` (`art_id`); 

SUCCESS! - https://github.com/keredson/peewee-db-evolve


Process finished with exit code 0

And every time I start up I get this:

Making updates to database: family_bot

Your database needs the following change:

  ALTER TABLE `users` ADD CONSTRAINT `fk_users_art_id_refs_arts` FOREIGN KEY (`art_id`) REFERENCES `arts` (`id`); 

Do you want to run this command? (yes or no) 

@zhekabourne
Copy link
Author

I understand that this is because there is no ENGINE=INNODB parameter in the CREATE TABLE query.
but how can i get peewee-db-evolve to do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant