Categories
Database Development

1822, “Failed to add the foreign key constraint. Missing index for constraint

I have 3 tables: users, photos, avatars (photo of user_1 that currently see user_2) when user deleted, all his photos and avatars, that shown to other users also removes What I do wrong? cursor.execute(“””CREATE TABLE IF NOT EXISTS users( id int AUTO_INCREMENT PRIMARY KEY, user_id INTEGER NOT NULL UNIQUE, goal VARCHAR(255) DEFAULT NULL, gender VARCHAR(255) […]

Categories
Mastering Development

importing PHP MySql database

I’m trying to import database to phpmyadmin the error is :- “”Error Static analysis: 3 errors were found during analysis. Variable name was expected. (near ” ” at position 5) Variable name was expected. (near ” ” at position 26) Unrecognized statement type. (near “Host” at position 0) SQL query: Host: localhost (Version: 5.6.16) # […]

Categories
Database Development

Proper way to create table friends in single statement

I have table users CREATE TABLE IF NOT EXISTS users( id int AUTO_INCREMENT PRIMARY KEY, user_id INTEGER NOT NULL UNIQUE, goal VARCHAR(255) DEFAULT NULL, age INTEGER DEFAULT NULL, gender VARCHAR(255) DEFAULT NULL, country VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, comment VARCHAR(255) DEFAULT NULL) I want to create table friends. One key feature that is […]

Categories
Database Development

Create table with predefined values from another table

I have a “users” table. DDL: cursor.execute(“””CREATE TABLE IF NOT EXISTS users( id int AUTO_INCREMENT PRIMARY KEY, user_id INTEGER NOT NULL UNIQUE, goal VARCHAR(255) DEFAULT NULL, age INTEGER DEFAULT NULL, gender VARCHAR(255) DEFAULT NULL, country VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, comment VARCHAR(255) DEFAULT NULL)”””) I want to create “show_usesr” table, DDL: cursor.execute(“””CREATE TABLE […]