I am writing a bot on python. At start in id are entered id, firstname, lastname, username. In the future, the user can send a phone number. Question: how to add by id? Or is it better to make a separate table with id and number and enter it there?

    1 answer 1

    Immediately create a table with columns: id, firstname, lastname, username, telephone (by default NULL), and when the user sends you a number, simply write it there.

    Example:

    from peewee import * class BaseModel(Model): class Meta: database = None # Π’ΡƒΡ‚ Ρ‚Π²ΠΎΡ‘ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ΠΊ Π‘Π” class User(BaseModel): id = PrimaryKeyField(primary_key=True, unique=True) firstname = CharField() lastname = CharField() username = CharField(unique=True) telephone = IntegerField(null=True, default=None) # Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠ³ΠΎ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ: user = User.create(firstname='Имя', lastname='Ѐамилия', username='НикнСйм') # Допустим ΠΎΠ½ прислал Π½ΠΎΠΌΠ΅Ρ€ user.telephone = 00000000000 user.save() user.update() 

    I advise you to use ORM right away as they greatly simplify life and speed up development.

    • Thanks, and if he sends the number through the button? - Yuri Popov
    • And the difference? You just get this number, and how this question to how your bot works. I did not quite understand what it means "through the button" - MrSmitix 3:42 pm