FlaskFM Project Step 14 Import Error

Hey there,
In the FlaskFM Project Step 14 i get a import error but I till now I could not figure out where the problem’s lying.

Following the two docs (app.py and models.py)

from flask import Flask, render_template

from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///song_library.db'


app.config['SECRET_KEY'] = 'you-will-never-guess'

#create an SQLAlchemy object named `db` and bind it to your app

db = SQLAlchemy(app)

#a simple initial greeting



def greeting():

    return render_template('greeting.html')

# app name 


def not_found(e): 

  return render_template("404.html") 

#uncomment the code below here when you are done creating database instance db and models

#import routes
from app import app, db

#the User model: each user has a username, and a playlist_id foreign key referring
#to the user's Playlist
class User(db.Model):
  id = db.Column(db.Integer, primary_key = True)
  username = db.Column(db.String(50), index = True, unique = True) 
  playlist_id = db.Column(db.Integer,  db.ForeignKey('playlist.id'))
  #representation method
  def __repr__(self):
    return "{} by {}".format(self.title, self.author)

#create the Song model here + add a nice representation method
  class Song(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    artist = db.Column(db.String(50), index=True, unique=True)
    title = db.Column(db.String(70), index=True, unique=True)
    n = db.Column(db.Integer, index=False, unique=False)
#create the Item model here + add a nice representation method
  class Item(db.Model):
    id =db.Column(db.Integer, primary_key = True)
    foreign_key = db.Column(db.Integer, db.ForeignKey("song.id"))

#create the Playlist model here + add a nice representation method
  class Playlist(db.Model):
    id =db.Column(db.Integer, primary_key = True)
    items = db.relationship('Item', backref='playlist', lazy='dynamic')

  class RelatedModel(db.Model):
    id = db.Column(db.Integer, primary_key = True)

  class MyModel(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    playlist_id = db.Column(db.Integer, db.ForeignKey('playlist.id')) #a foreign key

after step 13 I exited the terminal session as said
and then I executed “python3 add_data.py”

from the Terminal then I get always the following error

$ python3 add_data.py
Traceback (most recent call last):
File “add_data.py”, line 2, in
from models import Song, Playlist, Item, User
ImportError: cannot import name 'Song’

SOLVED it :blush: :blush:

Yo I’m having the same issue, how’d u solve it?

I tried an other code editor. Normally I use VS Code but it didn’t work with that.

At the moment I’m on vacation and do not have my laptop with me so I cannot say if I also changed smth on my code.

But as much as I can remember I just changed the code editor.

Have you already aksed on discord?
Often you’ll get faster a reply at least that’s what I’ve experienced.

I figured it out I accidentally like duplicated the data so i deleted song.py and redid the process